楼主: nuomin
446 1

Lisp Macros 2 [推广有奖]

  • 8关注
  • 61粉丝

版主

院士

34%

还不是VIP/贵宾

-

TA的文库  其他...

Lisp

计量模型入门与精通

威望
1
论坛币
170369 个
通用积分
8028.0780
学术水平
207 点
热心指数
257 点
信用等级
151 点
经验
947 点
帖子
2452
精华
0
在线时间
4062 小时
注册时间
2005-11-15
最后登录
2024-4-15

初级热心勋章 中级热心勋章 初级信用勋章

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
LispLanguage includes an extremely powerful (TuringComplete) macro facility. Via macros LispLanguage allows the user to adapt the language to their problem domain and in its ultimate expression, turn LispLanguage into a DomainSpecificLanguage (or LittleLanguage) customized for their task.
This page is for discussing how and when to use macros and for examples of macro use, see DoWeWantLispMacros for whether or not they should be used.
Uses of Macros
Macros are/should-be used for these reasons:
  • to deal with new data sub-languages (hide quote and quasiquote)
  • to introduce new binding operators
  • to specify control among the subexpressions of a form.
(From: http://www.cs.utah.edu/plt/mailarch/plt-scheme-2001/msg00292.html)
## this is only a limited view on macros. See my comment on macros and CLOS later on this page.
Macro Systems
There are three main macro systems in use:
Examples
Since I know that I use macros for deep, meaningful stuff, here are "prototypes" for the ones I consider interesting:
  (def-synonym-function synonym original)  (def-pipe-function function-name (input-stream output-stream &rest other-args) &body body)  (def-enumerated-value-domain control &rest data)  (let-gensyms symbols &body body)  This one is a very common idiom, except it's usually called something else.  (struct-comparison-predicate struct-name reducer-name &rest fields)  I need to rework the interface to this one.  (successive-character-predicate-parser input (&body predicates) &body body)  And even more so for this one.Three of these are convenience utilities; one is an "inconvenience utility" which I don't actually use anymore. One concisely defines a whole set of functions and symbols which relate to each other, in a manner which I very often want. The remaining two are nano-languages to simplify the writing of certain sorts of code. Most of these, I use quite often. I could expound the above at great length, but I expect it's not necessary to answer your question. -- DanielKnapp
Other common macros are:
  (when-bind var condition &body body)bind var to the result of condition and evaluate body if the condition returned true
  (with-collectors (collectors &body)COLLECTORS is a list of symbols, for each element of COLLECTORS a new function is introduced in BODY, these functions collect their arguments. WITH-COLLECTORS returns all of the collected arguments as multiple values. ie:
  (with-collectors (a b)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Macros Macro acr CRO ROS

沙发
三江鸿 发表于 2022-10-30 09:47:49 来自手机 |只看作者 |坛友微信交流群
点个赞加点人气
感谢分享

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-20 03:29