Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Macro-writing challenge

Name: Anonymous 2016-01-16 13:19

Write a macro check-arguments-non-nil to be used in function definitions, that would expand to assertion about every argument being non-nil.
The intended usage of this macro:

(defun foo (a b c d)
(check-arguments-non-nil)
foo-body)


This should expand to:

(defun foo (a b c d)
(assert (and (not (null a)) (not (null b)) (not (null c)) (not (null d)))
(a b c d)
"Null argument in FOO")
foo-body)


The macro must work whatever the number and names of the function parameters.

Name: Anonymous 2016-01-21 6:12

>>45
Does lisp allow this one use of the macro:
#define abc(x1,y1,z1) (z1+(x1*y1));res+x+c
#define runmacro2(macro,code1,code2,args...) ({code1;code2=macro(args) ;})
p("result is ",runmacro2(abc,;u8 c=1;,;u4 x=c+23;u8 res,1,2,4));//p prints arguments(this prints "result is 31")

>>46
Lisp hasn't failed, its just has "standards" on how to compose macros. Lisp macros are parsed at later stage than C macros: that means they have to obey more rules.
The way to fix this is to write Lisp program that manipulates text(preprocessor in Lisp) and feed it back to Lisp interpreter/compiler.
C preprocessor is more powerful only in the sense its unrestricted by anything(at actual macro processing its quite slow and primitive).
With one minor change C preprocessor would be made quite powerful, see:
http://w11.zetaboards.com/frozenbbs/topic/11501531/
for proposal.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List