Earlier quoted context omitted.
I thought a lot of Scheme implementations define IF in terms of COND. Is there some reason you're pointing this out? I should have been more detailed and noted that on the "by all means use it" vs. "if you think you need it, think again" continuum, EVAL requires IMO more justification than a macro. The source of my concern over macros is that when designing them, care needs to be taken to clearly communicate their se…
I'm not familiar with the arguments against using eval. Can you enlighten me as to why it would be a bad practice?
Is Scheme as good as Common Lisp?
21–25 of 25 posts
Re: Is Scheme as good as Common Lisp?
#22Earlier quoted context omitted.
here's one: (defmacro aif (test then &optional else) `(let ((it ,test)) (if it ,then ,else)))
In Scheme, the cases where one would use anaphoric IF can be handled using a COND clause with a "=>": (cond ((assoc 'key collection) => (lambda (it) (do-something-with it))) (else (alternative))) Alternatively, if you really wanted to create an AIF macro, you could use SYNTAX-RULES to create something that sugared up the above thusly: (aif it (assoc 'key collection) (do-something-with it) (alternative)) Or you could,…
Re: Is Scheme as good as Common Lisp?
#23Macros produce kickass code: http://neverfriday.com/blog/?p=10#more-10 If I didn't create a string-case= macro, I would have to write the final expression over and over again. With multiple string-case matches I would have to write string=? many many times: (cond ((or (string=? "hello" my-string) (string=? "world" my-string)) (print "match"))) To do that with the string-case= macro: (string-case= my-string (("hello"…
Re: Is Scheme as good as Common Lisp?
#24Macros produce kickass code: http://neverfriday.com/blog/?p=10#more-10 If I didn't create a string-case= macro, I would have to write the final expression over and over again. With multiple string-case matches I would have to write string=? many many times: (cond ((or (string=? "hello" my-string) (string=? "world" my-string)) (print "match"))) To do that with the string-case= macro: (string-case= my-string (("hello"…
(define (string-case= my-string . clauses)
(cond ((null? clauses) 'whatever)
((string-member? my-string (caar clauses))
((cadar clauses)))
(else (apply string-case=
my-string
(cdr clauses)))))
Where string-member? is trivial to define as a procedure too.Then you use it like
(string-case=
('("hello" "world")
(lambda () (print "match"))))
I myself wouldn't use a macro for this little gain.[Edit: I had completely misunderstood the macro.]
Re: Is Scheme as good as Common Lisp?
#25Earlier quoted context omitted.
In Scheme, the cases where one would use anaphoric IF can be handled using a COND clause with a "=>": (cond ((assoc 'key collection) => (lambda (it) (do-something-with it))) (else (alternative))) Alternatively, if you really wanted to create an AIF macro, you could use SYNTAX-RULES to create something that sugared up the above thusly: (aif it (assoc 'key collection) (do-something-with it) (alternative)) Or you could,…
I'm not much into macros yet, but while syntax-case is a R6RS feature, I thought there is a portable implementation that runs on top of R5RS? At least Chicken 2.6 provides that, and its implementor is viscerally against R6RS.