Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Quick question about lisp macros
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Greg Neumann  
View profile  
 More options Oct 14 2002, 9:49 am
Newsgroups: comp.lang.lisp
From: greg_new_...@yahoo.com (Greg Neumann)
Date: 14 Oct 2002 06:49:04 -0700
Local: Mon, Oct 14 2002 9:49 am
Subject: Quick question about lisp macros
Hello,

I'm learning scheme and also writing little utils in elisp.  But I'm
having the predictable frustrations.  Since lisp is a very fluid
language, is it simple to write macros so that elisp "feels" like
scheme?  All I really want is a basic define keyword that assigns
functions to both namespaces, and also have functions evaluate without
funcall.

I understand that the lisp community has innate hostilities towards
scheme advocacy and maybe it sounds like I'm bastardizing lisp or
writing unmaintainable code.  To me, it's just like converting from
one kind of machine to another I know better.  The irony is that maybe
I'll learn enough lisp that I won't want to actually use these macros
when I'm done...

TIA,
Greg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Bradshaw  
View profile  
 More options Oct 14 2002, 10:10 am
Newsgroups: comp.lang.lisp
From: Tim Bradshaw <t...@cley.com>
Date: 14 Oct 2002 15:05:28 +0100
Local: Mon, Oct 14 2002 10:05 am
Subject: Re: Quick question about lisp macros

* Greg Neumann wrote:
> I'm learning scheme and also writing little utils in elisp.  But I'm
> having the predictable frustrations.  Since lisp is a very fluid
> language, is it simple to write macros so that elisp "feels" like
> scheme?  All I really want is a basic define keyword that assigns
> functions to both namespaces, and also have functions evaluate without
> funcall.

I think this is intractable.  You can fairly easily *write* such a
macro, but many of its uses are illegal (at least in CL).  For
instance, the obvious:

(define x 3)

would try and set the FDEFINITION of X to be 3, which isn't legal - it
needs to be a function.  And even if this works it only solves some of
the `problems' - for instance.

    (defun gribble (fn ...)
      ...
      (fn ...))

is not going to work.

The differences between a lisp1 (like scheme) and a Lisp2 (like CL or
elisp) are not easily glossed over.  It would probably be easier to go
the other way.  In Scheme you can define FUNCTION as identity:

    (define (function x) x)

and then define FUNCALL:

    (define (funcall f . args)
      (apply f args))

And now it should be possible to write code which does, say:

    (funcall (function list) 1 2 3)

But this is pretty horrible, really.

If you really want to run scheme code n a lisp system what you need is
some kind of much larger compatibility box like pseudoscheme.  There's
probably something that goes the other way although in order to
emulate CL on top of a scheme you'd need a huge library...

--tim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Oct 14 2002, 11:56 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 14 Oct 2002 15:56:11 +0000
Local: Mon, Oct 14 2002 11:56 am
Subject: Re: Quick question about lisp macros
* Greg Neumann
| All I really want is a basic define keyword that assigns functions to
| both namespaces, and also have functions evaluate without funcall.

  Why is this a big deal to you?  What is it about people who learn Scheme
  first that makes this so terribly hard for them to cope with?

--
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas F. Burdick  
View profile  
 More options Oct 14 2002, 3:33 pm
Newsgroups: comp.lang.lisp
From: t...@whirlwind.OCF.Berkeley.EDU (Thomas F. Burdick)
Date: 14 Oct 2002 12:33:31 -0700
Local: Mon, Oct 14 2002 3:33 pm
Subject: Re: Quick question about lisp macros

Well, you can do this sort of thing in elisp.  For example, this:

  (defmacro define (name value)
    (let ((-value (gensym)))
      `(progn
        (let ((,-value ,value))
          (setf (symbol-function ',name) ,-value
                (symbol-value ',name) ,-value))
        ',name)))

  (defmacro lambda* (lambda-list &rest body)
    `(lambda ,lambda-list
      (letf ,(mapcar #'(lambda (var)
                         `((symbol-function ',var) ,var))
                     lambda-list)
        ,@body)))

will get you a Lisp-1 define and lambda*.  So you can now write
dumb-ass code like:

  (define foo
    (lambda* (x y z)
      (x y z)))

  (foo #'+ 1 2)
    => 3

It should be easy enough to write a Lisp-1 replacement for let.

Now, were you to try to write any amount of code using these you would
quickly realize how different elisp is from scheme, and would probably
regret having touched them.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Neumann  
View profile  
 More options Oct 15 2002, 12:58 am
Newsgroups: comp.lang.lisp
From: greg_new_...@yahoo.com (Greg Neumann)
Date: 14 Oct 2002 21:58:00 -0700
Subject: Re: Quick question about lisp macros

Erik Naggum <e...@naggum.no> wrote in message <news:3243599771779523@naggum.no>...
>   Why is this a big deal to you?  What is it about people who learn Scheme
>   first that makes this so terribly hard for them to cope with?

To me, it's just like converting from one kind of machine to another I
know better.  The irony is that maybe I'll learn enough lisp that I
won't want to actually use these macros when I'm done...

That's the cut 'n paste. :)  Intuitively, I think doing this project
gives me a rough sense of lisp's power and is a good tutorial.  But
it's not important enough to take a month and still not have anything
decent.

Greg Neumann


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg Neumann  
View profile  
 More options Oct 15 2002, 2:21 am
Newsgroups: comp.lang.lisp
From: greg_new_...@yahoo.com (Greg Neumann)
Date: 14 Oct 2002 23:21:32 -0700
Local: Tues, Oct 15 2002 2:21 am
Subject: Re: Quick question about lisp macros
t...@whirlwind.OCF.Berkeley.EDU (Thomas F. Burdick) wrote in message <news:xcv65w4ke7o.fsf@whirlwind.OCF.Berkeley.EDU>...

> Well, you can do this sort of thing in elisp.  For example, this:

Thanks for the demonstration-of-concept.  My emacs installation calls
the use of gensym a void-function error, but I can deal with that and
learn a bit in the process.

> Now, were you to try to write any amount of code using these you would
> quickly realize how different elisp is from scheme, and would probably
> regret having touched them.

Yup I'm a masochist.

Greg Neumann


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Oct 15 2002, 10:35 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 15 Oct 2002 14:35:08 +0000
Local: Tues, Oct 15 2002 10:35 am
Subject: Re: Quick question about lisp macros
* Greg Neumann
| My emacs installation calls the use of gensym a void-function error, but
| I can deal with that and learn a bit in the process.

  You have forgotten to say (require 'cl) to your Emacs.  This is not an
  installation issue, it is only a user issue.

--
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas F. Burdick  
View profile  
 More options Oct 15 2002, 1:40 pm
Newsgroups: comp.lang.lisp
From: t...@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick)
Date: 15 Oct 2002 10:40:29 -0700
Local: Tues, Oct 15 2002 1:40 pm
Subject: Re: Quick question about lisp macros

greg_new_...@yahoo.com (Greg Neumann) writes:
> t...@whirlwind.OCF.Berkeley.EDU (Thomas F. Burdick) wrote in message <news:xcv65w4ke7o.fsf@whirlwind.OCF.Berkeley.EDU>...
> > Well, you can do this sort of thing in elisp.  For example, this:

> Thanks for the demonstration-of-concept.  My emacs installation calls
> the use of gensym a void-function error, but I can deal with that and
> learn a bit in the process.

Er, yeah, I meant to preceed that with (require 'cl).  Everyone
programming in elisp should use the cl package.  Maybe you do or don't
want faked lexical scoping, and some of the other dubious features in
it, but you *really* want to use dolist and dotimes, for example,
rather than the equivalent hand-written loops using while.

> > Now, were you to try to write any amount of code using these you would
> > quickly realize how different elisp is from scheme, and would probably
> > regret having touched them.

> Yup I'm a masochist.

It might be amusing for a little bit, and might give you an
appreciation for how different the two languages are.  But I'd be wary
of getting used to it.  The semantics of the languages are different,
one's lexically-scoped, the other dynamically-scoped with no closures;
if you use lambda*, you get lisp-1 binding, but the rest of the elisp
world is using lisp-2 binding; etc.  I'd think the define vs
defun/defvar split would be a good thing -- if your brain is in the
wrong context, you'll hit syntax problems early, as opposed to
semantic problems later.

--
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                              
   |     ) |                              
  (`-.  '--.)                              
   `. )----'                              


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Paul Wallington  
View profile  
 More options Oct 16 2002, 7:26 pm
Newsgroups: comp.lang.lisp
From: John Paul Wallington <j...@shootybangbang.com>
Date: Thu, 17 Oct 2002 00:32:05 +0100
Local: Wed, Oct 16 2002 7:32 pm
Subject: Re: Quick question about lisp macros
t...@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick) wrote:

> Er, yeah, I meant to preceed that with (require 'cl).  Everyone
> programming in elisp should use the cl package.  Maybe you do or don't
> want faked lexical scoping, and some of the other dubious features in
> it, but you *really* want to use dolist and dotimes, for example,
> rather than the equivalent hand-written loops using while.

dolist and dotimes are defined in subr.el in Emacs 21.  Libraries
that use cl at runtime aren't installed in the Emacs distribution,
which may be a reason for people programming in elisp to avoid it.

--
John Paul Wallington


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Oct 17 2002, 10:26 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@cs.nyu.edu>
Date: 17 Oct 2002 10:28:17 -0400
Local: Thurs, Oct 17 2002 10:28 am
Subject: Re: Quick question about lisp macros

John Paul Wallington <j...@shootybangbang.com> writes:

> t...@apocalypse.OCF.Berkeley.EDU (Thomas F. Burdick) wrote:

> > Er, yeah, I meant to preceed that with (require 'cl).  Everyone
> > programming in elisp should use the cl package.  Maybe you do or don't
> > want faked lexical scoping, and some of the other dubious features in
> > it, but you *really* want to use dolist and dotimes, for example,
> > rather than the equivalent hand-written loops using while.

> dolist and dotimes are defined in subr.el in Emacs 21.  Libraries
> that use cl at runtime aren't installed in the Emacs distribution,
> which may be a reason for people programming in elisp to avoid it.

AFAIK dolist, dotimes, when, unless etc etc are a relatively new
addition to Elisp.  Before that they were defined only in the cl
module.

I think there is a resistance to CL in the Elisp camp.  Maybe it is
RMS himself.  I don't know.

In any case, there are no counter arguments for NOT sticking

        (require 'cl)

in your .emacs file.  If you want two arguments in favor:

        1 - defstruct
        2 - if you use ILISP you get it anyway. :)

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
715 Broadway 10th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »