William James
11/29/2015 1:06:00 AM
WJ wrote:
> Barry Margolin wrote:
>
> > > The crux of my question is not "can lisp do this" or "haskell rules" or
> > > anything like that. Simply that many of my initial thoughts on macros
> > > could also be formulated as functions, and I wanted to appreciate the
> > > real power and elegance of macros and the situations where one would
> > > prefer them over functions.
> >
> > The crux of the answer is that macros don't really provide too much that
> > you can't do with higher-order functions. Mostly what they provide is
> > syntactic sugar, so that it's easier to read and write these higher-order
> > constructs.
> >
> > For instance, you could define IF as:
> >
> > (defun if (test then-fun &optional (else-fun (lambda () nil)))
> > (funcall (cond (test then-fun)
> > (t else-fun))))
> >
> > and then it would be used as:
> >
> > (if (> x 100)
> > (lambda () (princ "X is really big!"))
> > (lambda () (princ "X isn't so big.")))
> >
> > Long ago most Lisp programmers decided that having lots of lambda
> > expressions all over the place like this was confusing, and macros allow
> > more concise syntax to be used. Haskell uses a more compact notation for
> > its anonymous functions, so it may be less of an issue there. And some
> > functional languages solve the problem using lazy evaluation.
>
> Gauche Scheme:
>
> (define (my-if test then-fun :optional (else-fun (lambda () #f)))
> (if test (then-fun) (else-fun)))
>
> (define x 0)
>
> (my-if (zero? x)
> (cut print "x is zero.")
> (cut print "99 / x is " (/ 99 x)))
Ocaml:
let my_if bool if_true if_false =
if bool then
Lazy.force if_true
else
Lazy.force if_false ;;
my_if (3>0) (lazy (9*9)) (lazy (8/0));;
===>
81
--
Jews may, as a result, perceive themselves to have a vital interest in
advocating a highly individualist, atomized gentile culture while
simultaneously maintaining their own highly elaborated collectivist subculture.
This is the perspective developed by the Frankfurt School and apparent
throughout Studies in Prejudice. --- Dr. Kevin MacDonald; "The Frankfurt School
of Social Research and the Pathologization of Gentile Group Allegiances"