News for hackers. Stuff that matters.
Re:Is Scheme as good as Common Lisp? by omouse on Friday August 31, 2007 @11:33AM (#48742)
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" "world")
    (print "match")))
Saves quite a bit of typing and now I have a good example of why macros are good to have around :D

edit: formatting ftw.

Re:Is Scheme as good as Common Lisp? by brlewis on Friday August 31, 2007 @12:54PM (#48780)
If you put spaces in front of your code, news.yc will indent nicely.

 (cond ((or (string=? "hello" my-string)
	    (string=? "world" my-string))
	(print "match")))

 (string-case= my-string
   (("hello" "world") (print "match")))
Re:Is Scheme as good as Common Lisp? by euccastro on Friday August 31, 2007 @07:32PM (#49042)
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? by centipede on Friday August 31, 2007 @07:16PM (#49035)
That should possible with a higher-order-function (and a lambda), too.