wangwil的个人空间 https://blog.eetop.cn/319972 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

ADS AEL programming

已有 4054 次阅读| 2014-11-12 13:29

近来对函数式编程非常着迷,我发现许多的EDA脚本语言均支持或有限度的支持函数式的编程风格,比如Cadence SKILL便是LISP的一个变种,
而Agilent ADS的脚本语言AEL也在有限度的支持函数式的编程,比如其内建的针对LIST的操作函数的命名对于一个有LISP的编程经历的人也倍感亲切。
作为练习,我以AEL实现了函数式编程中的一些经典的计算过程如折叠、映射等。

下面是其中一些AEL代码的片断,欢迎斧正。

defun foldl(f, z, xs) {
  if (xs == NULL) return z;
  else return foldl(f,call(f,list(z,car(xs))),cdr(xs));
}

defun foldr(f, z, xs) {
  if (xs == NULL) return z;
  else return call(f,list(car(xs), foldr(f, z, cdr(xs))));
}

defun mapcar(f,xs){
  if (xs == NULL) return NULL;
  else return cons(call(f,list(car(xs))), map(f,cdr(xs)));
}

//zip::[a]->[b]->[[a,b]]
defun zip(xs, ys){
  if (xs == NULL) return NULL;
  else return cons(list(car(xs),car(ys)),zip(cdr(xs),cdr(ys)));
}

defun plus(x,y) {return x+y;}

defun difference(x,y) {return x-y;}

defun minus(x) {return -x;}

defun times(x,y) {return x*y;}

defun add1(x) {return x+1;}

defun sum(xs) {return foldl(plus, 0, xs);}


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 0

    评论
  • 162

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-6 04:21 , Processed in 0.024711 second(s), 13 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部