From: Mr. Bojangles
Subject: Need some Lisp expertise
Date: 
Message-ID: <boblg4$t7l$1@news-int.gatech.edu>
Okay folks, you are smarter than I,

I have a macro that I am writing, and it takes in two arguments var and exp.

Inside the macro I am trying to map a lambda function to a give domain.

And for the lamda function I want the following:

(lambda (var) exp (some domain))

I am having a problem with getting the two arguments from the macro into the
lambda function..

Any suggestions?

If you need more information, let me know.

Cheers,

~MH
-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope

From: Kenny Tilton
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <0bdqb.62485$ri.10431777@twister.nyc.rr.com>
Hey, are they teaching Lisp at Georgia Texh? Cool.

Mr. Bojangles wrote:
> Okay folks, you are smarter than I,
> 
> I have a macro that I am writing, and it takes in two arguments var and exp.
> 
> Inside the macro I am trying to map a lambda function to a give domain.
> 
> And for the lamda function I want the following:
> 
> (lambda (var) exp (some domain))

Where is the mapping function? Tell you what, show a call and and an 
expansion, ala:

  call:
    (my-123-mapper n (+ n 2))
  get:
    (mapcar (lambda (n) (+ n 2)) '(1 2 3))

...so I can see what you are after.

kenny

> 
> I am having a problem with getting the two arguments from the macro into the
> lambda function..
> 
> Any suggestions?
> 
> If you need more information, let me know.
> 
> Cheers,
> 
> ~MH

-- 
http://tilton-technology.com

Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

Your Project Here! http://alu.cliki.net/Industry%20Application
From: Mr. Bojangles
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <bobnuj$11u$1@news-int.gatech.edu>
Kenny Tilton wrote:
> Hey, are they teaching Lisp at Georgia Texh? Cool.

Yeah AI class.

> Where is the mapping function? Tell you what, show a call and and an
> expansion, ala:
>
>   call:
>     (my-123-mapper n (+ n 2))
>   get:
>     (mapcar (lambda (n) (+ n 2)) '(1 2 3))
>
> ...so I can see what you are after.
>
> kenny

Okay,

(defmacro <name> (var expression)
 `(let (ret)
     (setf ret (map 'list #'(lambda (var) expression) (domain))
...

I basically want to be able to call (<name> x (> x 5)) and have that passed
into
lambda so that lambda ends up being (lambda x (> x 5) (domain)) doamin is
accessed seperately.

Ideas?

~MH

-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope
From: Kenny Tilton
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <eoeqb.62488$ri.10460084@twister.nyc.rr.com>
Mr. Bojangles wrote:
> Kenny Tilton wrote:
> 
>>Hey, are they teaching Lisp at Georgia Texh? Cool.
> 
> 
> Yeah AI class.
> 
> 
>>Where is the mapping function? Tell you what, show a call and and an
>>expansion, ala:
>>
>>  call:
>>    (my-123-mapper n (+ n 2))
>>  get:
>>    (mapcar (lambda (n) (+ n 2)) '(1 2 3))
>>
>>...so I can see what you are after.
>>
>>kenny
> 
> 
> Okay,
> 
> (defmacro <name> (var expression)
>  `(let (ret)
>      (setf ret (map 'list #'(lambda (var) expression) (domain))

Minor points: no need for the ret, and (map 'list ...) can be mapcar and 
we all got so tired of #'(lambda that you can just say (lambda..., so:

(defmacro <name> (var expression)
   `(mapcar (lambda (var) expression) (domain))

Note that you are a dead duck if there is no function or macro called 
DOMAIN. :)

Then if you expand that you get scary errors (depending un your 
implementation about "expression is unused" /and/ "expression is 
undefined". (or maybe one is at compile time and one when you compile 
the call? anyway, if you did expand you would see the macro "writes" the 
code:

    (mapcar (lambda (var) expression) (domain))

ie, that backquote ` at the beginning means what it says, "return these 
symbols just the way I wrote them". To get, custom stuff spliced into 
the larger form you have in mind, use the comma:

    `(mapcar (lamba (,var) ,expression) (domain))

All untested and typed fast and loose, but that's the basic idea.

btw, that <name> thing scares me. Do you want that parameterized as well?

kenny

> ...
> 
> I basically want to be able to call (<name> x (> x 5)) and have that passed
> into
> lambda so that lambda ends up being (lambda x (> x 5) (domain)) doamin is
> accessed seperately.
> 
> Ideas?
> 
> ~MH
> 

-- 
http://tilton-technology.com

Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

Your Project Here! http://alu.cliki.net/Industry%20Application
From: rif
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <wj0znfaeanm.fsf@five-percent-nation.mit.edu>
What's the difference between #'(lambda ... and (lambda ... ?
Can you always just use (lambda ... ?

rif
From: Peter Seibel
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <m34qxi9yah.fsf@javamonkey.com>
rif <···@mit.edu> writes:

> What's the difference between #'(lambda ... and (lambda ... ?
> Can you always just use (lambda ... ?

You can but only because there's a macro definition that expands
(lambda ...) in a value position into #'(lambda ...). It was--as I
understand it--added to the Common Lisp definition in order to make it
possible to write a ISLISP compatibility package in pure Common Lisp.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Mr. Bojangles
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <boc4m7$6kj$1@news-int.gatech.edu>
Kenny Tilton wrote:
>     `(mapcar (lamba (,var) ,expression) (domain))

So this maybe works a little better than you intended. The reason that I
don't want to post my EXACT code is because I don't want to violate my
school's academic honesty policy. But I will reproduce as much as I can. I
am implementing first order logic (forall, thereexists, etc.). I will
reproduce the macro below with some things changed. When I change something
I will surround it with angular <> brackets. That's what <name> meant in the
last post.

(defmacro <name> (var expression)
  (let (ret)
    (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
      (loop for i from 0 to (- (length ret) 1) do
        <loop on the ret list and return a value>

So now when I use debugging to print out what ret is I get:
ret is: (MAPCAR #'(LAMBDA (X) (> X 12)) (DOMAIN))

instead of what that statement evaluates to. Which is:
(nil nil nil nil nil nil nil nil nil nil)

I don't know why this doesn't evaluate.

Ideas... comments?

~MH


-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope
From: Kenny Tilton
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <tkhqb.62614$ri.10557622@twister.nyc.rr.com>
Mr. Bojangles wrote:
> Kenny Tilton wrote:
> 
>>    `(mapcar (lamba (,var) ,expression) (domain))
> 
> 
> So this maybe works a little better than you intended. The reason that I
> don't want to post my EXACT code is because I don't want to violate my
> school's academic honesty policy. 

OK, I won't give you the fish.

But I will reproduce as much as I can. I
> am implementing first order logic (forall, thereexists, etc.). I will
> reproduce the macro below with some things changed. When I change something
> I will surround it with angular <> brackets. That's what <name> meant in the
> last post.
> 
> (defmacro <name> (var expression)
>   (let (ret)
>     (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
>       (loop for i from 0 to (- (length ret) 1) do
>         <loop on the ret list and return a value>

OK, assume the lotus position and stare at a candle until 
macroexpansion-time and runtime no longer appear as One. The hard part 
of macro writing is keeping these two times separate, esp since the 
backquote and comma let you jump between them in the middle of a form.

A macro is a function that receives your code after the reader has 
converted it into symbolic form and returns some transformed symbolic 
form, which the compiler then compiles into code to run at some later 
date. In those Lisps which include an interpreter, the steps are back to 
back, but still separate.

Here is what I did as a macro newbie. Right after the (setf ret...), put 
a print statement. print the contents of ret, the type-of ret, and the 
type-of (car ret) etc etc. You'll discover that backquote is just a 
fancy quote that lets you swap in values via the comma thing.

You seem to have code outside the backquote trying to actually do the 
runtime work of forall etc. The code implementing FORALL is what should 
be returned (in symbolic form). The macro function should simply cobble 
together code in symbolic form that when /later/ run will do what you 
want. You are writing code (the macro) to write other code (an expansion 
which will get kicked off at runtime).

Stare at these and try to get clear what the macro function is doing 
(producing what macroexpand-1 shows you) and what the produced code does 
(the FORALL semantics). Then make sure the right code goes inside or 
outside the backquote (the first two examples are intended to emphasize 
that the macro function builds up a symbolic expression; backquote is 
just a (huge) convenience:

(defmacro printnumba-1 (numba)
    (list 'print (* 2 numba)))

(macroexpand-1 '(printnumba-1 21))

(defmacro printnumba-2 (numba)
    (list 'print `(* 2 ,numba)))

(macroexpand-1 '(printnumba-2 21))

(defmacro printnumba-3 (var numba)
    `(dotimes (,var 2)
       (print (+ 2 ,numba))))

(macroexpand-1 '(printnumba-3 x 21))

Like I said, it is hairy because there are these two modalities being 
juggled at once. Use print statements and follow the earlier link to On 
Lisp for good stuff on macros.

kenny



> 
> So now when I use debugging to print out what ret is I get:
> ret is: (MAPCAR #'(LAMBDA (X) (> X 12)) (DOMAIN))
> 
> instead of what that statement evaluates to. Which is:
> (nil nil nil nil nil nil nil nil nil nil)
> 
> I don't know why this doesn't evaluate.
> 
> Ideas... comments?
> 
> ~MH
> 
> 

-- 
http://tilton-technology.com

Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

Your Project Here! http://alu.cliki.net/Industry%20Application
From: Mr. Bojangles
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <boco3q$fp2$1@news-int.gatech.edu>
Thanks for your help everyone, I think I got it... I backquoted the loop,
that seemed to fix it.

~MH

-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope
From: Thomas F. Burdick
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <xcvy8uuynso.fsf@famine.OCF.Berkeley.EDU>
"Mr. Bojangles" <···········@cc.gatech.edu> writes:

> Thanks for your help everyone, I think I got it... I backquoted the loop,
> that seemed to fix it.

"That seemed to fix it" doesn't imply a deep level of understanding.
At a certain point it should click, and macros become really easy, so
my advice would be to keep working at it.  Advice that I've seen work
well for an Elisp user was: don't use backquote.  It's a great
shorthand notation, but sometimes it makes newbies feel like they're
writing magical incantation, which is a bad thing.  Try just using
LIST, LIST*, CONS, and ' for a bit.  And auxiliary functions that take
a piece of code, and return the result of a transformation.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Peter Seibel
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <m3n0ba55bf.fsf@javamonkey.com>
···@famine.OCF.Berkeley.EDU (Thomas F. Burdick) writes:

> "Mr. Bojangles" <···········@cc.gatech.edu> writes:
> 
> > Thanks for your help everyone, I think I got it... I backquoted the loop,
> > that seemed to fix it.
> 
> "That seemed to fix it" doesn't imply a deep level of understanding.
> At a certain point it should click, and macros become really easy, so
> my advice would be to keep working at it.  Advice that I've seen work
> well for an Elisp user was: don't use backquote.  It's a great
> shorthand notation, but sometimes it makes newbies feel like they're
> writing magical incantation, which is a bad thing.  Try just using
> LIST, LIST*, CONS, and ' for a bit.

A variant of the same thing--if one wants to become one with backquote
and is the kind of person who sort of *likes* playing scales--is to
sit down with section 2.4.6 of the HyperSpec and make up backquoted
expressions of varying complexity and expand them according to the
rules given there and then simplify the resulting mess back down to
equivalent but readable code. Then check that typing the backquoted
expression and the code you came up with yields the same results.

After you've done this with a few expressions, I predict you'll have
stripped backquote of any magical aura it used to have and understand
it as what it is--a concise syntax for stuff that otherwise would be a
mild pain to write by hand.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Peter Seibel
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <m34qxi8d9j.fsf@javamonkey.com>
Kenny Tilton <·······@nyc.rr.com> writes:

> Mr. Bojangles wrote:
> > Kenny Tilton wrote:
> >
> >>    `(mapcar (lamba (,var) ,expression) (domain))
> > So this maybe works a little better than you intended. The reason
> > that I
> > don't want to post my EXACT code is because I don't want to violate my
> > school's academic honesty policy.
> 
> OK, I won't give you the fish.
> 
> But I will reproduce as much as I can. I
> > am implementing first order logic (forall, thereexists, etc.). I will
> > reproduce the macro below with some things changed. When I change something
> > I will surround it with angular <> brackets. That's what <name> meant in the
> > last post.
> > (defmacro <name> (var expression)
> >   (let (ret)
> >     (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
> >       (loop for i from 0 to (- (length ret) 1) do
> >         <loop on the ret list and return a value>
> 
> OK, assume the lotus position and stare at a candle until
> macroexpansion-time and runtime no longer appear as One. The hard
> part of macro writing is keeping these two times separate, esp since
> the backquote and comma let you jump between them in the middle of a
> form.

Or, Mr. Bojangles, for another perspective on the same thing, see the
article I just posted in the "Question about design, defmacro,
macrolet, and &environment" thread that outlines four steps of macro
development. If you can show Step 1 and Step 2 of that process, we can
probably help you with Step 3 and 4. Or--more likely--once you've got
the steps clear, you'll be able to do 3 and 4 yourself.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Thomas A. Russ
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <ymioevpwd5k.fsf@sevak.isi.edu>
"Mr. Bojangles" <···········@cc.gatech.edu> writes:

By the way, I am favorably impressed by your attention to the honor
rules at Georgia Tech.

> (defmacro <name> (var expression)
>   (let (ret)
>     (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
>       (loop for i from 0 to (- (length ret) 1) do
>         <loop on the ret list and return a value>

Since others have answered the substantive questions, I'll just post a
couple of Lisp programming style notes.  The main ones are that
generally, Lisp programmers tend to avoid SETing variables, prefering
either to bind them with LET forms or nest calls.  The other is that
indexing into lists is generally considered a bad idea because they are
sequential access data structures rather than random access.  With those
in mind, the following are transformed versions of the code that are
stylistically more in keeping with Lisp.  I'll also add in the 

Pass one: Binding the variable & changing the loop construct:

(defmacro <name> (var expression)
  `(let ((ret (mapcar #'(lambda (,var) ,expression) (domain))))
      (loop for element in ret do 
        <loop on the ret list and return a value>)))

Pass two:  Nesting the call and eliminating the "ret" variable entirely

(defmacro <name> (var expression)
  `(loop for element in (mapcar #'(lambda (,var) ,expression) (domain)) do 
	 <loop on the ret list and return a value>))

The return construct from LOOP should be sufficient to get the
appropriate value out of the mapped list and return it.  If you are
curious about exploring the algorithm you are using here a bit more, you
could also arrange things so that you only evaluate the expression on
elements of the domain until you find the one you want to return.  It
has a slightly different structure, though.


> So now when I use debugging to print out what ret is I get:
> ret is: (MAPCAR #'(LAMBDA (X) (> X 12)) (DOMAIN))
> 
> instead of what that statement evaluates to. Which is:
> (nil nil nil nil nil nil nil nil nil nil)
> 
> I don't know why this doesn't evaluate.

Because that's what macros do.  They don't evaluate their arguments, but
instead produce code that is evaluated later.  If this isn't clear from
other replies, I (or someone else :) can expand on it.


-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Mr. Bojangles
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <bofcse$jn9$1@news-int.gatech.edu>
Thomas A. Russ wrote:
>
> By the way, I am favorably impressed by your attention to the honor
> rules at Georgia Tech.
>
Thank you.

Now that the project is past due, I will post the entire problem to see if
your advice changes.

***START PROBLEM***

In utils.lisp you will find two sets of definitions. The first is
get-lisp-symbols. As noted above, it returns a bunch of LISP symbols. The
second set includes the prove macro. It takes a first-order logic expression
to be evaluated and a domain of interest and evaluates that expression in
the context of that domain. For example, it can be invoked like this:


  ;; Prove: There is some integer between 1 and 10 that is greater
  ;; than five
  (prove (thereexists x (> x 5)) (integers 1 10))
     ---> T (or at least some non-NIL value)

  ;; Prove: All numbers between 1 and 10 are equal
  (prove (forall x (forall y (= x y))) (integers 1 10))
     ---> NIL

  ;; Prove: All numbers between 1 and 1 are equal
  (prove (forall x (forall y (= x y))) (integers 1 1))
     ---> T (or at least some non-NIL value)

  ;; Prove: In LISP, there exists some symbol bound to a list
  (prove (thereexists x (and (boundp x) (listp (eval x))))
(get-lisp-symbols))
     ---> T (or at least some non-NIL value)*** FROM UTILS.lisp ***;;; A
simple macro that accepts a first order sentence in LISP syntax;;; and a
domain, executing that sentence in that domain.;;;;;; In particular, prove
executes domain and stores the result in the;;; global variable *domain*
which is accessible by executing the;;; form: (domain)(defvar *domain*
nil)(defmacro prove (form domain)  `(let ((*domain* ,domain))
,form))(defun domain () *domain*)
*** END PROBLEM ***My implementation is sorry, I kind of avoid the whole
macro issue and just make it call a function. Which I know is not right.***
MY IMPLEMENTATION ***;;Implementation of forall
;;(forall var expression)
(defmacro forall (var expression)
  (let (ret)
    (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
    `(loop for i from 0 to (- (length ,ret) 1) do
       (cond
 ((equal(nth i ,ret) nil)(return nil))
 (t nil))
       finally (return t))))


;;Implementation of thereexists
;;(thereexists var expression)
(defmacro thereexists (var expression)
  (let (ret)
    (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
    `(loop for i from 0 to (- (length ,ret) 1) do
       (cond
 ((not(equal(nth i ,ret) nil))(return t))
 (t nil))
       finally (return nil))))


So now you can see the whole problem. The way I implemented it doesn't
handled nested clauses. I'm pretty sure I just did it plain wrong. I'm not a
newbie in any sense of the word, I simply had a very difficult time
understanding where I should go with this.

Thanks for you comments and help.
-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope
From: Mr. Bojangles
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <bofcuk$jnh$1@news-int.gatech.edu>
Wow the formatting of that is awful, sorry guys.

~MH


-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope
From: Mr. Bojangles
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <bofd5u$jon$1@news-int.gatech.edu>
Let's try again.

*START PROBLEM**

In utils.lisp you will find two sets of definitions. The first is
get-lisp-symbols. As noted above, it returns a bunch of LISP symbols. The
second set includes the prove macro. It takes a first-order logic expression
to be evaluated and a domain of interest and evaluates that expression in
the context of that domain. For example, it can be invoked like this:


  ;; Prove: There is some integer between 1 and 10 that is greater
  ;; than five
  (prove (thereexists x (> x 5)) (integers 1 10))
     ---> T (or at least some non-NIL value)

  ;; Prove: All numbers between 1 and 10 are equal
  (prove (forall x (forall y (= x y))) (integers 1 10))
     ---> NIL

  ;; Prove: All numbers between 1 and 1 are equal
  (prove (forall x (forall y (= x y))) (integers 1 1))
     ---> T (or at least some non-NIL value)

  ;; Prove: In LISP, there exists some symbol bound to a list
  (prove (thereexists x (and (boundp x) (listp (eval x))))
(get-lisp-symbols))
     ---> T (or at least some non-NIL value)


*** FROM UTILS.lisp ***

(defvar *domain* nil)
(defmacro prove (form domain)
  `(let ((*domain* ,domain))
     ,form))
(defun domain () *domain*)


*** MY IMPLEMENTATION ***

(defmacro forall (var expression)
  (let (ret)
    (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
    `(loop for i from 0 to (- (length ,ret) 1) do
       (cond
 ((equal(nth i ,ret) nil)(return nil))
 (t nil))
       finally (return t))))


(defmacro thereexists (var expression)
  (let (ret)
    (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
    `(loop for i from 0 to (- (length ,ret) 1) do
       (cond
 ((not(equal(nth i ,ret) nil))(return t))
 (t nil))
       finally (return nil))))


So now you can see the whole problem. The way I implemented it doesn't
handled nested clauses. I'm pretty sure I just did it plain wrong. I'm not a
newbie in any sense of the word, I simply had a very difficult time
understanding where I should go with this.

Thanks for you comments and help.




-- 
Matt Horstman CS Junior | "I do benefits for all
Georgia Institute of Technology | religions, I'd hate
·····@cc.gatech.edu | to blow the hereafter on a
Phone: 404.206.9197 | technicality" -Bob Hope
From: ·············@comcast.net
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <znf51czx.fsf@comcast.net>
"Mr. Bojangles" <···········@cc.gatech.edu> writes:

> Let's try again.
>
> *START PROBLEM**
>
> In utils.lisp you will find two sets of definitions. The first is
> get-lisp-symbols. As noted above, it returns a bunch of LISP symbols. The
> second set includes the prove macro. It takes a first-order logic expression
> to be evaluated and a domain of interest and evaluates that expression in
> the context of that domain. For example, it can be invoked like this:
>
>
>   ;; Prove: There is some integer between 1 and 10 that is greater
>   ;; than five
>   (prove (thereexists x (> x 5)) (integers 1 10))
>      ---> T (or at least some non-NIL value)
>
>   ;; Prove: All numbers between 1 and 10 are equal
>   (prove (forall x (forall y (= x y))) (integers 1 10))
>      ---> NIL
>
>   ;; Prove: All numbers between 1 and 1 are equal
>   (prove (forall x (forall y (= x y))) (integers 1 1))
>      ---> T (or at least some non-NIL value)
>
>   ;; Prove: In LISP, there exists some symbol bound to a list
>   (prove (thereexists x (and (boundp x) (listp (eval x))))
> (get-lisp-symbols))
>      ---> T (or at least some non-NIL value)
>
>
> *** FROM UTILS.lisp ***
>
> (defvar *domain* nil)
> (defmacro prove (form domain)
>   `(let ((*domain* ,domain))
>      ,form))
> (defun domain () *domain*)
>
>
> *** MY IMPLEMENTATION ***
>
> (defmacro forall (var expression)
>   (let (ret)
>     (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
>     `(loop for i from 0 to (- (length ,ret) 1) do
>        (cond
>  ((equal(nth i ,ret) nil)(return nil))
>  (t nil))
>        finally (return t))))
>
>
> (defmacro thereexists (var expression)
>   (let (ret)
>     (setf ret `(mapcar #'(lambda (,var) ,expression) (domain)))
>     `(loop for i from 0 to (- (length ,ret) 1) do
>        (cond
>  ((not(equal(nth i ,ret) nil))(return t))
>  (t nil))
>        finally (return nil))))

The reason FORALL and THEREEXISTS have to be macros is because they
are binding forms.  This suggests that you could transform them to
a lambda expression to implement the binding, and call a function
to implement the logic behind the form.

The variable being bound is VAR, but the value being bound to is each
element (in turn) of *domain*, so it will have to appear in the macro
expansion as well.  The hyperspec documents the EVERY and SOME
functions that do what we want (although I can't see an easy way to
find out about these other than reading the whole spec).

(defmacro forall (var expression)
  `(EVERY (LAMBDA (,var) ,expression) *DOMAIN*))

(defmacro thereexists (var expression)
  `(SOME (LAMBDA (,var) ,expression) *DOMAIN*))
From: Peter Seibel
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <m38ymu9yd8.fsf@javamonkey.com>
Kenny Tilton <·······@nyc.rr.com> writes:

> Minor points: no need for the ret, and (map 'list ...) can be mapcar
> and we all got so tired of #'(lambda that you can just say (lambda...,
> so:

Speak for yourself, Mister. IMHO using (lambda ...) instead of
#'(lambda ...) indicates latent Schemish tendencies. True CLers wear
#' as a badge of honor.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Thomas F. Burdick
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <xcv1xsm0yid.fsf@famine.OCF.Berkeley.EDU>
Peter Seibel <·····@javamonkey.com> writes:

> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> > Minor points: no need for the ret, and (map 'list ...) can be mapcar
> > and we all got so tired of #'(lambda that you can just say (lambda...,
> > so:
> 
> Speak for yourself, Mister. IMHO using (lambda ...) instead of
> #'(lambda ...) indicates latent Schemish tendencies. True CLers wear
> #' as a badge of honor.

Don't worry, it'll pass ;-)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Kenny Tilton
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <ikgqb.62611$ri.10515931@twister.nyc.rr.com>
Peter Seibel wrote:
> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> 
>>Minor points: no need for the ret, and (map 'list ...) can be mapcar
>>and we all got so tired of #'(lambda that you can just say (lambda...,
>>so:
> 
> 
> Speak for yourself, Mister. IMHO using (lambda ...) instead of
> #'(lambda ...) indicates latent Schemish tendencies. True CLers wear
> #' as a badge of honor.

<sigh> How does that go? "No one more fanatical than the recently 
converted."?

:)

-- 
http://tilton-technology.com

Why Lisp? http://alu.cliki.net/RtL%20Highlight%20Film

Your Project Here! http://alu.cliki.net/Industry%20Application
From: ·············@comcast.net
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <vfpyust0.fsf@comcast.net>
Peter Seibel <·····@javamonkey.com> writes:

> Kenny Tilton <·······@nyc.rr.com> writes:
>
>> Minor points: no need for the ret, and (map 'list ...) can be mapcar
>> and we all got so tired of #'(lambda that you can just say (lambda...,
>> so:
>
> Speak for yourself, Mister. IMHO using (lambda ...) instead of
> #'(lambda ...) indicates latent Schemish tendencies. True CLers wear
> #' as a badge of honor.

In my case it indicates laziness.  Why type two extra characters (one
of 'em is shifted, even).

Not to mention the extra 2 spaces of indentation.
From: Alain Picard
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <87vfpyt7v7.fsf@memetrics.com>
Peter Seibel <·····@javamonkey.com> writes:

> Speak for yourself, Mister. IMHO using (lambda ...) instead of
> #'(lambda ...) indicates latent Schemish tendencies. True CLers wear
> #' as a badge of honor.
>

Interestingly enough, I use #'(lambda when I'm thinking
of a function (99% of the time), but (lambda when I'm
thinking of a sexp (usually splicing/backquoting).
Anybody else do this?  I'm not sure why it feels
"psychologically right".

Oh, and, I've never used Scheme... so no tendencies, unless
they're from a prior life.
From: Pascal Costanza
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <boe7pl$7ln$2@newsreader2.netcologne.de>
Peter Seibel wrote:

> Kenny Tilton <·······@nyc.rr.com> writes:
> 
> 
>>Minor points: no need for the ret, and (map 'list ...) can be mapcar
>>and we all got so tired of #'(lambda that you can just say (lambda...,
>>so:
> 
> 
> Speak for yourself, Mister. IMHO using (lambda ...) instead of
> #'(lambda ...) indicates latent Schemish tendencies. True CLers wear
> #' as a badge of honor.

I always use (lambda ...), never #'(lambda ...). It's not that hard to 
remember what is going on in the background IMHO.

I also started to appreciate using (function ...) instead of #'..., 
especially when giving Lisp code examples to newbies.


Pascal
From: Christopher C. Stacy
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <uoevq3wlu.fsf@dtpq.com>
>>>>> On Wed, 05 Nov 2003 21:58:34 GMT, Kenny Tilton ("Kenny") writes:
 Kenny> and we all got so tired of #'(lambda that you can just say (lambda...,

I always write (and prefer to see) it written as #'(lambda ...
From: Coby Beck
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <bod333$22e6$1@otis.netspace.net.au>
"Kenny Tilton" <·······@nyc.rr.com> wrote in message
····························@twister.nyc.rr.com...
> we all got so tired of #'(lambda that you can just say (lambda..., so:
>
> (defmacro <name> (var expression)
>    `(mapcar (lambda (var) expression) (domain))

I like the #' for the visual emphasis it gives.  lambda is special, it
deserves a little bling-bling :-) (word of the day)

-- 
Coby Beck
(remove #\Space "coby 101 @ big pond . com")
From: Barry Margolin
Subject: Re: Need some Lisp expertise
Date: 
Message-ID: <bcdqb.381$lK3.363@news.level3.com>
In article <············@news-int.gatech.edu>,
Mr. Bojangles <···········@cc.gatech.edu> wrote:
>Okay folks, you are smarter than I,
>
>I have a macro that I am writing, and it takes in two arguments var and exp.
>
>Inside the macro I am trying to map a lambda function to a give domain.
>
>And for the lamda function I want the following:
>
>(lambda (var) exp (some domain))
>
>I am having a problem with getting the two arguments from the macro into the
>lambda function..

You're not very clear about what you're trying to do, but I'm guessing you
want something like:

(defmacro map-over-domain (var exp)
  `(mapcar (lambda (,var) ,exp) (some domain)))

-- 
Barry Margolin, ··············@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.