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
Idiot's guide to special variables take 2
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
  Messages 51 - 75 of 129 - Collapse all  -  Translate all to Translated (View all originals) < Older  Newer >
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
 
Erann Gat  
View profile  
 More options Nov 16 2002, 1:12 am
Newsgroups: comp.lang.lisp
From: g...@jpl.nasa.gov (Erann Gat)
Date: Fri, 15 Nov 2002 21:32:34 -0800
Local: Sat, Nov 16 2002 12:32 am
Subject: Re: Idiot's guide to special variables take 2
In article <pan.2002.11.16.01.12.33.431...@consulting.net.nz>, "Adam

Warner" <use...@consulting.net.nz> wrote:
> There is no splitting hairs. It is logic/set theory.

Are you kidding?  That's the very definition of splitting hairs!

E.


 
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.
Alain Picard  
View profile  
 More options Nov 16 2002, 1:15 am
Newsgroups: comp.lang.lisp
From: Alain Picard <apicard+die-spammer-...@optushome.com.au>
Date: 16 Nov 2002 16:55:01 +1100
Local: Sat, Nov 16 2002 12:55 am
Subject: Re: Idiot's guide to special variables take 2

thelif...@gmx.net (thelifter) writes:
> Alain Picard <apicard+die-spammer-...@optushome.com.au> wrote in message <news:87r8dnoxy2.fsf@optushome.com.au>...
> > Ok, try this.  Forget the word "variable" for a moment.  There ARE no
> > "variables".  There are only symbols and values.  When you evaluate an

> I just took a look at the language specification. It seems that the
> main problem is, that there is no definition for variable:

Please understand that I offered this explanation in the context
of a guide "for idiots" (God I hate that term).  Of course there
_are_ variables, both in execution and in the spec---refer to Kent's
reply to my previous post to see what that's all about.

But if you want to get a temporary mental model for how things
work, I offered you one.  It's, by design, incomplete and inaccurate.


 
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 1:31 am
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 16 Nov 2002 07:31:18 +0100
Local: Sat, Nov 16 2002 1:31 am
Subject: Re: Idiot's guide to special variables take 2

Erik Naggum <e...@naggum.no> writes:
> * Nils Goesche
> | And here is where I erred: There /is/ a global lexical
> | environment; it is called the null lexical environment, and
> | it is here where the binding is established.

>   This is very confused.  The "null lexical environment"
>   communicates to the alert reader that there are no lexically
>   apparent bindings, not that any new bindings are established
>   in it.

Well, yes.  Maybe I shouldn't use the term ``null lexical
environment´´ when talking about it.

>   That `eval´ is evaluated in the null lexical environment
>   means that it cannot access lexically apparent bindings,
>   which `eval´ does not attempt to capture bindings when it
>   receives a form.

Sure.  What I am trying to understand is the following:

CL-USER 30 > (eval 'most-positive-double-float)
1.7976931348623165E308

CL-USER 31 > (setf (symbol-value 'x) 42)
42

CL-USER 32 > (eval 'x)
42

There is indeed no lexically apparent binding for those two
symbols.  But their values are looked up somewhere, in an
environment.  Which is it?

The global environment, obviously, which is also called ``null
lexical environment´´ to emphasize that it contains no lexically
apparent bindings (see 3.1.1.3.1 The Null Lexical Environment).
Neither MOST-POSITIVE-DOUBLE-FLOAT nor X have been declaimed
special, however.

Now, MOST-POSITIVE-DOUBLE-FLOAT is a constant, which is not so
interesting, but X is not.  I can do

CL-USER 33 > (setf (symbol-value 'x) 17)
17

CL-USER 34 > (eval 'x)
17

anytime I want.  I can also do

CL-USER 35 > (let ((x 13))
               (+ x 5))
18

I would also like to try the following:

(defun test (y)
  (+ x y))

(let ((x 20))
  (test 7))

Now, 3.2.2.3 Semantic Constraints says:

# Special proclamations for dynamic variables must be made in the
# compilation environment. Any binding for which there is no
# special declaration or proclamation in the compilation
# environment is treated by the compiler as a lexical binding.

But I might snottily claim that I don't want X to be special,
anyway :-)

But what the heck, let's do it anyway:

CL-USER 36 > (defun test (y)
               (+ x y))
Warning: Syntactic warning for form X:
   X assumed special.
TEST

CL-USER 37 > (let ((x 20))
               (test 7))
24

as expected.  

Whether this is legal code or not is not so interesting at the
moment; what I like is that we can explain everything that
happened in the above experiments without resorting to
implementation issues if we simply say that X is part of such a
thing as a ``global lexical environment´´.  While this sounds a
bit like an oxymoron because lexical bindings are usually
lexically restricted to establishing forms and have dynamic
extent, it is well possible to give the term a reasonable
meaning.

Now, what happens if we do

CL-USER 38 > (declaim (special x))
NIL

CL-USER 39 > (let ((x 20))
               (test 7))
27

By globally declaring X special, we instruct the system to
perform the last binding in the dynamic environment, instead.  It
is rather puzzling that TEST already behaves accordingly, too!
So, now X is also part of the (global) dynamic environment,
obviously.  And it has kept its value :-)

Christian Queinnec writes in ``Lisp in Small Pieces´´ (p. 50):

# In addition, if we do not find the dynamic value, then we go
# back to the global lexical environment, since it also serves as
# the global dynamic environment in Common Lisp.

> [split explanations]

Thank you for those, but I think I already understood this.  The
above is the point I am a bit confused about :-)

Note that my problem does not stem from confusing symbols with
variables.  My (SETF SYMBOL-VALUE) actions are one thing, not
very interesting; the interesting part is explaining the
evaluations, semantically.

All these considerations are certainly rather esoteric, idle
speculation.  What /really/ goes on under the hood in the
implementation is perfectly clear, anyway; but I find it
interesting, anyway.

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 1:47 am
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 16 Nov 2002 07:47:57 +0100
Local: Sat, Nov 16 2002 1:47 am
Subject: Re: Idiot's guide to special variables take 2

g...@jpl.nasa.gov (Erann Gat) writes:
> In article <87heeich36....@darkstar.cartan>, Nils Goesche <n...@cartan.de> wrote:

> > Sure, but the more interesting case is how you would bring
> > (SETF SYMBOL-VALUE) back.

> <shrug>

> (defun (setf symbol-value) (value symbol)
>   (set symbol value))

> or if that was too cute

> (defun (setf symbol-value) (value symbol)
>   (eval `(locally (declare (special ,symbol)) (setq ,symbol ,value))))

Ok, and the interesting part is that your code does not look like
it manipulates a data structure, anymore.  You are using only
abstract operators for setting variables.  I can achieve the same
thing in bash:

#!/bin/bash

set_symbol_value () {
        eval "$1=$2"

}

x=2

set_symbol_value x 4

echo $x

will output 4.  The values don't come from a symbol data
structure anymore but have to be explained purely semantically.

> > It is interesting insofar as it emphasizes that you don't
> > need SYMBOL-VALUE to understand variables in Common Lisp, I
> > think.

> You don't need the symbol-value function, but I don't see how
> you can understand variables in CL without the *concept* of a
> symbol's value (or its dynamic binding or whatever you want to
> call it).

By not calling it the ``symbol's´´ value.  Variables have values;
a symbol is just some arbitrary data structure.  Sure, Lisp code
is made up of conses and symbols, but as soon as it is
/evaluated/, it doesn't matter anymore what kind of thing a
symbol actually is and if it has something like a value slot or
not.  That's an implementation issue.  As soon as a symbol is
evaluated (and it is not a symbol macro ;-), it is used to denote
the /name/ of a /variable/.  The level of abstraction is higher.

> BTW, a number of people have written to me to say that symbols
> have nothing to do with lexical bindings.  This is false.  The
> semantics of lexical bindings in Common Lisp are defined in
> such a way that a compiler *may* optimize away the symbols, but
> the semantics of lexical variables are defined in the standard
> in terms of symbols.  (Also, most implementations keep the
> symbols around for debugging.)

This is just a variation of the above.

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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.
Erann Gat  
View profile  
 More options Nov 16 2002, 3:56 am
Newsgroups: comp.lang.lisp
From: g...@jpl.nasa.gov (Erann Gat)
Date: Sat, 16 Nov 2002 00:47:08 -0800
Local: Sat, Nov 16 2002 3:47 am
Subject: Re: Idiot's guide to special variables take 2

In article <87vg2yau3m....@darkstar.cartan>, Nils Goesche <n...@cartan.de> wrote:
> The values don't come from a symbol data structure anymore

But they never did.  Who said anything about a symbol data structure?

Here's another implementation of symbol-value:

(let ((env (make-hash-table)))
  (defun symbol-value (s) (gethash env s))
  (defun (setf symbol-value) (value s)
    (setf (gethash env s) value))))

Using this implementation you can set the symbol-value of any Lisp object,
not just symbols.

E.


 
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.
Harald Hanche-Olsen  
View profile  
 More options Nov 16 2002, 8:17 am
Newsgroups: comp.lang.lisp
From: Harald Hanche-Olsen <han...@math.ntnu.no>
Date: 16 Nov 2002 13:50:26 +0100
Local: Sat, Nov 16 2002 7:50 am
Subject: Re: Idiot's guide to special variables take 2
+ Erik Naggum <e...@naggum.no>:

| My God, how annoying it is to try to explain something to people who
| are unwilling to listen because they believe they already understand
| things better than their teachers.

Yeah, but I still prefer the student who tells me I am wrong, as long
as he gives a reason for thinking so.  It is only if he persists after
his mistake has been pointed out to him that he becomes annoying.

I am not denying that this often happens on Usenet, of course.

--
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Yes it works in practice - but does it work in theory?


 
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.
Harald Hanche-Olsen  
View profile  
 More options Nov 16 2002, 8:17 am
Newsgroups: comp.lang.lisp
From: Harald Hanche-Olsen <han...@math.ntnu.no>
Date: 16 Nov 2002 13:42:28 +0100
Local: Sat, Nov 16 2002 7:42 am
Subject: Re: Idiot's guide to special variables take 2
+ Nils Goesche <n...@cartan.de>:

| Harald Hanche-Olsen <han...@math.ntnu.no> writes:
|
| > Only if you worry about such esoterica as how to construct the
| > natural numbers given nothing more than set theory do you dream
| > up seemingly crazy schemes such as 0={} (the empty set), 1={0},
| > 2={0,1}, etc.
|
| I don't see what's crazy about that.

Neither do I, which is why I wrote "seemingly".  But when I was first
exposed to the idea, way back in the mists of time, I did think it was
crazy, at least until the idea began to sink in and I realized the
elegance of it all (as you describe so eloquently).

| The question ``What /is/ a variable, after all?´´ is likewise
| interesting.

Even more so in mathematics than in computing, methinks.  I have never
understood why the induction principle seems to be so difficult to
grasp, but it is an observable fact that many students fail to get
it.  Actually, I think it is not the induction principle /per se/ that
confuses people, but that they have a more fundamental problem in
understanding what mathematics is all about, and in particular in
grasping the notion of a variable.  If you haven't got a firm grip on
that, a proof by induction really seems circular, and so the students
are left wondering why they are told not to employ circular reasoning,
and yet, within the framework of induction, it is OK to do so?

I think the situation is very similar with respect to the notion of
variables in Lisp.  Once you get it, it is blindingly obvious, but
when you try to explain this insight, you're still groping for words.
(And personally, I find I still struggle with the terminology, as
evidenced by an earlier posting of mine in this thread.)

--
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Yes it works in practice - but does it work in theory?


 
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 11:39 am
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 16 Nov 2002 17:39:07 +0100
Local: Sat, Nov 16 2002 11:39 am
Subject: Re: Idiot's guide to special variables take 2

Sure.  But the very notations (symbol-value 'x) or (setf
(symbol-value 'x) 42) look exactly as if somebody did a
(defstruct symbol ((value ...) ...) before.  We are talking about
conceptual models for describing the semantics of Lisp variables.
If you avoid, for the moment, the SYMBOL-VALUE way of accessing a
(dynamic) variable's value it becomes clearer, for beginners,
that this is about evaluation, scope and environments of
variables and that you can perfectly understand their behavior
without thinking of a symbol as a data structure with a slot that
contains the value of the variable it denotes (which would give
you the wrong idea for lexical variables, anyway).  As I said,
Lisp code is made up of symbols and conses (and other atoms!),
but as soon as we are trying to describe the semantics of the
/code/ this tree structure of objects /represents/, it is better
to get away as far as possible from the physical representation
of our code when we describe its /meaning/.  Once this has been
understood, and only then, we can get to the additional cutie
that we can /also/ access the /semantic/ value of a dynamic
variable by accessing a physical ``value´´ slot of the symbol,
the data structure, that is used to represent it.

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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.
Erann Gat  
View profile  
 More options Nov 16 2002, 11:57 am
Newsgroups: comp.lang.lisp
From: g...@jpl.nasa.gov (Erann Gat)
Date: Sat, 16 Nov 2002 08:51:33 -0800
Local: Sat, Nov 16 2002 11:51 am
Subject: Re: Idiot's guide to special variables take 2

In article <87ptt6cr3a....@darkstar.cartan>, Nils Goesche <n...@cartan.de> wrote:
> The question ``What /is/ a variable, after all?´´ is likewise
> interesting.

Indeed.

The standard says:

A variable is a binding in the variable namespace.
A binding is an association between a name and that which the name denotes.
A namespace is [a set of] bindings whose denotations are restricted to a
particular kind.

My latest attempt to distill this for a revised version of TIG2SV:

A variable is a storage location that has a name.  (Or a variant suggested
by Len Charest: a variable is a storage location that is identified by an
identifier.)

E.

---

<tangent>

On a challenge from Crispin Sartwell's website I once took a stab at
trying to define the word "seven".  Here's what I came up with FWIW:

ZERO is a description of the non-existence of things.  It is usually
applied to a particular kind of thing defined by a particular set of
properties within a particular context.  "There are zero cows in my
office" means that within the context of my office there does not exist a
thing with the set of properties for which we use the shorthand notation
"cow".

ONE is a description of a particular kind of existence characterized by
the following property: there exists ONE (thing) if and only if it is not
possible to partition it into a subset and its complement such that both
the subset and its complement have the properties that define it.  If you
have ONE cow then it is not possible to partition that cow into a subset
and its complement such that both the subset and its complement are cows.

Note that this partitioning is a *mental* partitioning, not a physical
one.  This allows us to, for example, take a collection of cows and call
it ONE herd of cows by stipulating that one of the essential properties
that defines a herd is that it have a boundary beyond which there are no
cows.

TWO is a description of a particular kind of existence characterized by
the following property: there exist TWO (things) if and only if it is
possible to partition the context within which they exist into a subset
and its complement such that there is ONE in the subset and ONE in the
complement.

Note that there is an asymmetry here.  To decide whether there is ONE of
something you have to partition the THING, but to decide whether there is
TWO of something you have to partition the CONTEXT.  Thus, for some
collections of cows, it can be correct to say that there is both ONE and
TWO herds of cows depending on exactly how you choose to define a herd.

In general, if it is possible to partition a context such that there are X
in the subset and Y in the complement then we say that there exist X PLUS
Y.  Thus, TWO is ONE PLUS ONE.  THREE is TWO PLUS ONE (which is the same
as ONE PLUS ONE PLUS ONE) etc.  Seven is three plus two plus two.


 
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 12:56 pm
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 16 Nov 2002 18:55:54 +0100
Local: Sat, Nov 16 2002 12:55 pm
Subject: Re: Idiot's guide to special variables take 2

Quite good.  I would like to be able to say ``A binding is an
association between a name and a storage location.´´  This takes
into account that the same name can denote different locations in
different contexts.  A variable would simply be a name, then, I
guess.

> <tangent>

> On a challenge from Crispin Sartwell's website I once took a
> stab at trying to define the word "seven".  Here's what I came
> up with FWIW:

Heh, nice.  Call me weird, but I think that nothing can beat the
poetic beauty of the correct answer, though:

(defun define (n)
  (labels ((pprint-k (n)
             (pprint-logical-block (nil nil :prefix "{" :suffix "}")
               (dotimes (i n)
                 (pprint-k i)
                 (when (< i (1- n))
                   (write-string ", ")
                   (pprint-newline :fill))))))
    (let ((*print-pretty* t)
          (*print-right-margin* 72))
      (pprint-k n))
    (values)))

CL-USER 15 > (define 7)
{{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}},
 {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}}},
 {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}},
  {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}}}},
 {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}},
  {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}}},
  {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}},
   {{}, {{}}, {{}, {{}}}, {{}, {{}}, {{}, {{}}}}}}}}

:-)

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 1:59 pm
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 16 Nov 2002 19:59:07 +0100
Local: Sat, Nov 16 2002 1:59 pm
Subject: Re: Idiot's guide to special variables take 2

I <n...@cartan.de> wrote:
> While this sounds a bit like an oxymoron because lexical
> bindings are usually lexically restricted to establishing forms
> and have dynamic extent, [...]

Oops, scratch that dynamic extent thing.

Sorry,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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 Nov 16 2002, 2:23 pm
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 16 Nov 2002 19:23:15 +0000
Local: Sat, Nov 16 2002 2:23 pm
Subject: Re: Idiot's guide to special variables take 2
* Nils Goesche
| The global environment, obviously, which is also called ``null
| lexical environment´´ to emphasize that it contains no lexically
| apparent bindings (see 3.1.1.3.1 The Null Lexical Environment).

  No, this is not right.  That two things are the same in one respect does
  not make them the same in all respects, which they would have to be to be
  interchangeable.  It is like `not´ and `null´.

| Whether this is legal code or not is not so interesting at the moment;
| what I like is that we can explain everything that happened in the above
| experiments without resorting to implementation issues if we simply say
| that X is part of such a thing as a ``global lexical environment´´.

  But there is no such thing.  The whole point is that it is /not/ lexical.

| Christian Queinnec writes in ``Lisp in Small Pieces´´ (p. 50):
|
| # In addition, if we do not find the dynamic value, then we go
| # back to the global lexical environment, since it also serves as
| # the global dynamic environment in Common Lisp.

  I believe this is more accurate for Scheme.

| What /really/ goes on under the hood in the implementation is perfectly
| clear, anyway; but I find it interesting, anyway.

  When the implementation is clear and the concepts are not, the conceptual
  model is wrong.

--
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 2:37 pm
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 16 Nov 2002 20:37:48 +0100
Local: Sat, Nov 16 2002 2:37 pm
Subject: Re: Idiot's guide to special variables take 2

Erik Naggum <e...@naggum.no> writes:
> * Nils Goesche
> | Christian Queinnec writes in ``Lisp in Small Pieces´´ (p. 50):
> |
> | # In addition, if we do not find the dynamic value, then we go
> | # back to the global lexical environment, since it also serves as
> | # the global dynamic environment in Common Lisp.

>   I believe this is more accurate for Scheme.

Yes, probably.

> | What /really/ goes on under the hood in the implementation is
> | perfectly clear, anyway; but I find it interesting, anyway.

>   When the implementation is clear and the concepts are not,
>   the conceptual model is wrong.

Heh, quite right.  I'll go think about it some more.

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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.
Gareth McCaughan  
View profile  
 More options Nov 16 2002, 11:38 pm
Newsgroups: comp.lang.lisp
From: Gareth McCaughan <Gareth.McCaug...@pobox.com>
Date: Sun, 17 Nov 2002 04:33:04 +0000
Local: Sat, Nov 16 2002 11:33 pm
Subject: Re: Idiot's guide to special variables take 2

That's not "the correct answer", any more than the correct
answer to "What is a symbol?" is something like

    struct Symbol {
      LispObject * package;
      LispObject * name;
      LispObject * value;
    };

In other words, it's one implementation of the number 7
(better: it's the number 7 in one implementation of the
natural numbers). There are others, such as {{{{{{{{}}}}}}}}
and { x : |x| = 7 } (er, obviously the latter won't do as it
stands; it also won't work in ZF set theory, but it's fine
in something like NF).

ObLisp:

(defstruct box x0 y0 x1 y1 children bordered)

(defun box-size (b)
  (values (- (box-x1 b) (box-x0 b))
          (- (box-y1 b) (box-y0 b))))

(defun box-translate (b dx dy)
  (make-box :x0 (+ (box-x0 b) dx)
            :y0 (+ (box-y0 b) dy)
            :x1 (+ (box-x1 b) dx)
            :y1 (+ (box-y1 b) dy)
            :children (loop for child in (box-children b)
                            collect (box-translate child dx dy))
            :bordered (box-bordered b)))

(defun box-translate-to (b x y)
  (box-translate b (- x (box-x0 b)) (- y (box-y0 b))))

(defun box-surround (b delta)
  (make-box :x0 (- (box-x0 b) delta)
            :y0 (- (box-y0 b) delta)
            :x1 (+ (box-x1 b) delta)
            :y1 (+ (box-y1 b) delta)
            :children (list b)
            :bordered nil))

(defun bordered (b) (setf (box-bordered b) t) b)

(defun box-adjoin (b1 b2 delta direction)
  (multiple-value-bind (x1 y1) (box-size b1)
    (multiple-value-bind (x2 y2) (box-size b2)
      (ecase direction
        ((:h)
         (make-box :x0 0 :y0 0
                   :x1 (+ x1 x2 (* 3 delta))
                   :y1 (+ (max y1 y2) (* 2 delta))
                   :children (list (box-translate-to b1 delta delta)
                                   (box-translate-to b2 (+ x1 (* 2 delta)) delta))
                   :bordered nil))
        ((:v)
         (make-box :x0 0 :y0 0
                   :x1 (+ (max x1 x2) (* 2 delta))
                   :y1 (+ y1 y2 (* 3 delta))
                   :children (list (box-translate-to b1 delta delta)
                                   (box-translate-to b2 delta (+ y1 (* 2 delta))))
                   :bordered nil))))))

(defun flip (direction)
  (ecase direction
    ((:h) :v)
    ((:v) :h)))

(defun numerals (n size delta direction)
  (if (zerop n)
    (box-surround (make-box :x0 0 :y0 0 :x1 size :y1 size :bordered t) delta)
    (box-adjoin (numeral n size delta (flip direction))
                (numerals (1- n) size delta (flip direction))
                delta
                direction)))

(defun numeral (n size delta direction)
  (if (zerop n)
    (make-box :x0 0 :y0 0 :x1 size :y1 size :bordered t)
    (bordered (numerals (1- n) size delta direction))))

(defun flatten (b)
  (let ((rest (loop for child in (box-children b) nconc (flatten child))))
    (if (box-bordered b)
      (cons (list (box-x0 b) (box-y0 b) (box-x1 b) (box-y1 b)) rest)
      rest)))

(defun show-flattened (boxes dx dy &optional (stream t))
  (princ "%!PS
/box { /y1 exch def /x1 exch def /y0 exch def /x0 exch def
       x0 y0 moveto x1 y0 lineto x1 y1 lineto x0 y1 lineto closepath stroke }
     bind def
"  stream)
  (loop for (x0 y0 x1 y1) in boxes do
    (format stream "~A ~A ~A ~A box~%" (+ x0 dx) (+ y0 dy) (+ x1 dx) (+ y1 dy)))
  (princ "showpage
" stream))

(with-open-file (f "10.ps" :direction :output)
  (show-flattened (flatten (numeral 10 3 3 :v)) 30 30 f))

This is rather nasty code in several ways, but its output is
rather lovely.

--
Gareth McCaughan  Gareth.McCaug...@pobox.com
.sig under construc


 
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.
Nils Goesche  
View profile  
 More options Nov 16 2002, 11:52 pm
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 17 Nov 2002 05:52:36 +0100
Local: Sat, Nov 16 2002 11:52 pm
Subject: Re: Idiot's guide to special variables take 2

I know.  I meant it is my favorite among the correct answers.
And it is certainly the most poetic ;-)

> (with-open-file (f "10.ps" :direction :output)
>   (show-flattened (flatten (numeral 10 3 3 :v)) 30 30 f))

> This is rather nasty code in several ways, but its output is
> rather lovely.

Very cool indeed.  Thanks for this!

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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.
Aleksandr Skobelev  
View profile  
 More options Nov 17 2002, 5:44 am
Newsgroups: comp.lang.lisp
From: Aleksandr Skobelev <public-m...@list.ru>
Date: 17 Nov 2002 12:46:50 +0300
Local: Sun, Nov 17 2002 4:46 am
Subject: Re: Idiot's guide to special variables take 2

Erik Naggum <e...@naggum.no> writes:
> * Nils Goesche
> | The global environment, obviously, which is also called ``null
> | lexical environment´´ to emphasize that it contains no lexically
> | apparent bindings (see 3.1.1.3.1 The Null Lexical Environment).

>   No, this is not right.  That two things are the same in one respect does
>   not make them the same in all respects, which they would have to be to be
>   interchangeable.  It is like `not´ and `null´.

Speaking frankly, I don't understand clearly what this phrase in
`3.1.1.3.1 The Null Lexical Environment' means:

    "The null lexical environment is equivalent to the global
     environment."

What the equivalence do they speak about? Do they mean that, like the
global environment, the null lexical environment contains no lexical
bindings? Or it might be that they speak about an equivalency in a sense
of bindings for functions and macros and proclamations/declarations? I'm
confused. :(


 
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.
Kent M Pitman  
View profile  
 More options Nov 17 2002, 11:51 am
Newsgroups: comp.lang.lisp
From: Kent M Pitman <pit...@world.std.com>
Date: Sun, 17 Nov 2002 16:51:03 GMT
Local: Sun, Nov 17 2002 11:51 am
Subject: Re: Idiot's guide to special variables take 2

g...@jpl.nasa.gov (Erann Gat) writes:
> I assumed he meant something deeper: no great harm would come if we
> eliminated the functionality that symbol-value provides, under whatever
> guises that functionality exists in the language (including the ability to
> evaluate symbols at run time).

(eval '*foo*) would still exist.

 
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.
Nils Goesche  
View profile  
 More options Nov 17 2002, 1:56 pm
Newsgroups: comp.lang.lisp
From: Nils Goesche <n...@cartan.de>
Date: 17 Nov 2002 19:56:50 +0100
Local: Sun, Nov 17 2002 1:56 pm
Subject: Re: Idiot's guide to special variables take 2

As I understand it, it means that whenever it says that a form is
evaluated in the null lexical environment, like the argument to
EVAL, for instance, it cannot access any lexically apparent
bindings.  The only bindings it /can/ access are those in the
global environment and the current dynamic environment, but /no/
lexical ones.

> Do they mean that, like the global environment, the null
> lexical environment contains no lexical bindings?

Yes.  I was only wondering about if it would make sense to
/introduce/ a notion of a global lexical binding when speaking
about Common Lisp to make it easier to explain some freaky code
snippets of questionable legal status.  But whatever it was I was
talking about it wasn't Common Lisp as defined by the HyperSpec.

> I'm confused. :(

I hope it wasn't me who caused that :-)

Regards,
--
Nils Gösche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0


 
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 Nov 17 2002, 7:59 pm
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 18 Nov 2002 00:59:33 +0000
Local: Sun, Nov 17 2002 7:59 pm
Subject: Re: Idiot's guide to special variables take 2
* Aleksandr Skobelev
| What the equivalence do they speak about?

  Sigh.  It means that when somebody says the "null lexical environment",
  the expressin contains relevant information about (at least) two things:
  (1) the perspective and (2) the object.  The same holds for "the global
  environment", of course, in which case the object is the same as for the
  previous expression, but the /perspective/ is not.

| Do they mean that, like the global environment, the null lexical
| environment contains no lexical bindings?

  The global environment is what you get when you have no lexical bindings.

  The point here is that the lexical environment shadows the global.  When
  you have an empty/null lexical environment, you have nothing that could
  shadow the global environment, therefore the consequence of viewing your
  environment through the now empty/transparent lexical environment is that
  you see only the background global environment.  But it is possible to
  look at the global environment /without/ looking through a transparent
  lexical environment that shadows nothing, hence the two perspectives have
  different names.

  Think of bindings as squares on a blackboard.  You can flip overlays over
  the blackboard from both sides, and the overlays can have opaque squares
  that shadow any other bindings but otherwise be transparent.  Now, the
  overlays attached to one side holds overlays for special bindings while
  the other side holds lexical overlays, so you can flip them in from both
  sides.  A `special´ proclamation means that you cut a whole in all the
  lexical overlays so that you will always see the dynamic bindings.  When
  you make a special binding, you make an opaque square on an overlay you
  have flipped in from the special side and scribble on it.  When you make a
  lexical binding, you make an opaque square on an overlay you have flipped
  in from the lexical side and scribble on it.  When you call a function,
  you temporarily remove all your lexical overlays, but the special overlays
  remain, and you use a fresh set of lexical overlays.  Now, if you make no
  lexical bindings on this fresh set of overlays, you have the null lexical
  environment.  This is what `eval´ starts out with, just like any other
  function before it makes its own lexical bindings, such as for incoming
  arguments (which may also cause special bindings, btw).

  Did that make the issue opaque or transparent?

  And, please, there is no global lexical environment.  While some evidently
  think it is descriptive of something, it is an oxymoron that only confuses
  people who do not understand what is going on.

--
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.
Rob Warnock  
View profile  
 More options Nov 18 2002, 3:34 am
Newsgroups: comp.lang.lisp
From: r...@rpw3.org (Rob Warnock)
Date: Mon, 18 Nov 2002 02:34:29 -0600
Local: Mon, Nov 18 2002 3:34 am
Subject: Re: Idiot's guide to special variables take 2
Nils Goesche  <n...@cartan.de> wrote:
+---------------
| As I understand it, it means that whenever it says that a form is
| evaluated in the null lexical environment, like the argument to
| EVAL, for instance, it cannot access any lexically apparent
| bindings.  The only bindings it /can/ access are those in the
| global environment and the current dynamic environment, but /no/
| lexical ones.
+---------------

Well, it *can*, of course, access any new lexical bindings introduced
in the expression being EVAL'd, as well as any lexical bindings
previously closed over by functions called by the EVAL'd code. You
didn't really mean to exclude those when you said "/no/ lexical ones",
did you?

To me, to say that "a form is evaluated in the null lexical environment"
means that the *current* lexical environment is not accessible.

-Rob

-----
Rob Warnock, PP-ASEL-IA         <r...@rpw3.org>
627 26th Avenue                 <URL:http://www.rpw3.org/>
San Mateo, CA 94403             (650)572-2607


 
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.
Aleksandr Skobelev  
View profile  
 More options Nov 18 2002, 9:15 am
Newsgroups: comp.lang.lisp
From: Aleksandr Skobelev <public-m...@list.ru>
Date: 18 Nov 2002 17:12:39 +0300
Local: Mon, Nov 18 2002 9:12 am
Subject: Re: Idiot's guide to special variables take 2

Nils Goesche <n...@cartan.de> writes:
> Aleksandr Skobelev <public-m...@list.ru> writes:
> >     "The null lexical environment is equivalent to the global
> >      environment."

> > What the equivalence do they speak about?

> As I understand it, it means that whenever it says that a form is
> evaluated in the null lexical environment, like the argument to
> EVAL, for instance, it cannot access any lexically apparent
> bindings.  The only bindings it /can/ access are those in the
> global environment and the current dynamic environment, but /no/
> lexical ones.

Yes, but there is nothing about the current dynamic environment in that
statement. So, it looks like we give some free interpretation for it.

> > Do they mean that, like the global environment, the null
> > lexical environment contains no lexical bindings?

> Yes.  I was only wondering about if it would make sense to
> /introduce/ a notion of a global lexical binding when speaking
> about Common Lisp to make it easier to explain some freaky code
> snippets of questionable legal status.

Hmm, I'm not sure about how such a notion could be useful. It might be
that some examples of such freaky code (if you can find some easily)
could clear it.

> > I'm confused. :(

> I hope it wasn't me who caused that :-)

I'm afraid, I do it myself. :)

 
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.
Aleksandr Skobelev  
View profile  
 More options Nov 18 2002, 9:15 am
Newsgroups: comp.lang.lisp
From: Aleksandr Skobelev <public-m...@list.ru>
Date: 18 Nov 2002 16:45:54 +0300
Local: Mon, Nov 18 2002 8:45 am
Subject: Re: Idiot's guide to special variables take 2

Hmm. It might be there is a mess in my poor head, but how about dynamic
environments?

----------
* (setf x 10)
Warning: This variable is undefined:
  X

10
* (let ((x 20))
    (declare (special x))
    (let ((x 30))
      (print x)
      (eval 'x)))
30
20
*
----------

Here the lexical binding to 30 shadows the dynamic binding to 20, which
is in dynamic, but not the global environment. But eval sees 20, not 10.
So, isn't null lexical environment equivalent to a some dynamic + the
global environment?

Sorry, I'm afraid I became enmeshed who has been overlaid by whom here. :)

Thank you. I think (well, I hope) I understand how fresh lexical/dynamic
bindings shadow each other and bindings in the global environment. What I
don't understand clear (and what I wrote about in my previous message) is
the usage of 'equivalent' word in the standard. Does it have the strict
technical or just some free, descriptive meaning? Just now it looks for
me like it is just descriptive and not absolutly full (if remember about
bindings in dynamic environments). But I suspect, that it might be
something wrong in my reasoning. :(

>   And, please, there is no global lexical environment.  While some evidently
>   think it is descriptive of something, it is an oxymoron that only confuses
>   people who do not understand what is going on.

Hear!


 
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.
Nils Goesche  
View profile  
 More options Nov 18 2002, 9:21 am
Newsgroups: comp.lang.lisp
From: Nils Goesche <car...@cartan.de>
Date: 18 Nov 2002 15:21:47 +0100
Local: Mon, Nov 18 2002 9:21 am
Subject: Re: Idiot's guide to special variables take 2

Of course not.  Maybe I should say ``any bindings lexically apparent
to EVAL where it is called´´.

> To me, to say that "a form is evaluated in the null lexical
> environment" means that the *current* lexical environment is not
> accessible.

Of course.

Regards,
--
Nils Gösche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0


 
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.
Nils Goesche  
View profile  
 More options Nov 18 2002, 9:30 am
Newsgroups: comp.lang.lisp
From: Nils Goesche <car...@cartan.de>
Date: 18 Nov 2002 15:30:22 +0100
Local: Mon, Nov 18 2002 9:30 am
Subject: Re: Idiot's guide to special variables take 2

I added ``the current dynamic environment´´ because EVALed forms can
access it (see dictionary entry for EVAL) /and/ the null lexical
environment:

CL-USER 133 > (defvar *foo* 42)
*FOO*

CL-USER 134 > *foo*
42

CL-USER 135 > (let ((*foo* 40))
                (eval '(+ *foo* 2)))
42

works as well (*FOO* coming from the current dynamic environment) as

CL-USER 136 > (eval '(logand #xFF most-positive-fixnum))
255

(MOST-POSITIVE-FIXNUM available in the null lexical environment,
because it is part of the global environment).

> > > Do they mean that, like the global environment, the null
> > > lexical environment contains no lexical bindings?

> > Yes.  I was only wondering about if it would make sense to
> > /introduce/ a notion of a global lexical binding when speaking
> > about Common Lisp to make it easier to explain some freaky code
> > snippets of questionable legal status.

> Hmm, I'm not sure about how such a notion could be useful. It might
> be that some examples of such freaky code (if you can find some
> easily) could clear it.

I doubt it, but I posted some earlier in this thread.

Regards,
--
Nils Gösche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0


 
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.
Nils Goesche  
View profile  
 More options Nov 18 2002, 9:40 am
Newsgroups: comp.lang.lisp
From: Nils Goesche <car...@cartan.de>
Date: 18 Nov 2002 15:40:02 +0100
Local: Mon, Nov 18 2002 9:40 am
Subject: Re: Idiot's guide to special variables take 2

Nice example, actually.  Although you should somehow globally declare
X special, maybe by using DEFPARAMETER instead of just SETF, to clear
all doubt.

> Here the lexical binding to 30 shadows the dynamic binding to 20,
> which is in dynamic, but not the global environment. But eval sees
> 20, not 10.  So, isn't null lexical environment equivalent to a some
> dynamic + the global environment?

No.  EVAL can access /both/ a null lexical environment (meaning the
lexically apparent binding of x to 30 isn't visible) /and/ the current
dynamic environment.  This is a specialty of EVAL (see its dictionary
entry) but has nothing to do with the term ``null lexical
environment´´ in itself.

Regards,
--
Nils Gösche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0


 
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.
Messages 51 - 75 of 129 < Older  Newer >
« Back to Discussions « Newer topic     Older topic »