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
Message from discussion Binding in defparameter versus let
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
 
Björn Lindberg  
View profile  
 More options Sep 13 2012, 8:12 am
Newsgroups: comp.lang.lisp
From: bj...@runa.se (Björn Lindberg)
Date: Thu, 13 Sep 2012 14:12:03 +0200
Local: Thurs, Sep 13 2012 8:12 am
Subject: Re: Binding in defparameter versus let

parisni...@gmail.com writes:
> Today I was cleaning up some code and made a mistake.

> The code was originally like this
> (defparameter *baz* (list 'a #'(lambda()(third *baz*)) 'c))

> Now *baz* is bound early enough that the lambda works properly.

> It failed when I moved it into a function:

> (defun foo ()
>   (let ((bar (list 'a #'(lambda()(third bar)) 'c)))
>     (print bar)))

> The binding for let doesn't occur until running, so (third bar) is unbound.

> This can be easily remedied with:
> (defun foo ()
>   (let ((bar))
>     (setf bar (list 'a #'(lambda()(third bar)) 'c))
>     (print bar)))

> Are there neater ways to do the same thing?

You can achieve the *same effect* by not going through the variable at
all:

  (defun foo ()
    (let ((bar #1=(list 'a #'(lambda () (third #1#)) 'c)))
      (funcall (second bar))))

  (foo) => C

Bj rn Lindberg


 
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.