Live data from Hacker News

Is Scheme as good as Common Lisp?

news.ycombinator.com

21–25 of 25 posts

Re: Is Scheme as good as Common Lisp?

#21
post #17

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?

Because EVAL is an atomic bomb, and there's no need to use it when a garrote would more elegantly perform the task at hand.

Re: Is Scheme as good as Common Lisp?

#22
post #13
post #9

Earlier 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,…

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.

Re: Is Scheme as good as Common Lisp?

#23
post #7

Macros 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"…

That should possible with a higher-order-function (and a lambda), too.

Re: Is Scheme as good as Common Lisp?

#24
post #7

Macros 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"…

That only saves you one quote and one lambda for each clause, right?

  (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?

#25
post #13

Earlier 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.

Yes, SYNTAX-CASE has been around for quite a while, and there is a portable implementation that has just a few prerequisites beyond what R5RS provides.

http://www.cs.indiana.edu/chezscheme/syntax-case/

Post reply on HN