though the following line works:
((lambda (x) (+ x 1)) 1)
(2)
And it is possible to define a function tmp that is only visible inside
another function f?
TIA,
--
jb
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
jblazi <jbl...@hotmail.com> wrote:
>(1)
>Why does something like this not work:
> (setq f (lambda (x) (+ x 1)))
> (f 3)
>though the following line works:
>((lambda (x) (+ x 1)) 1)
(funcall f 3)
Btw, you should use distinct symbol names for global variables, like
*f*.
>(2)
>And it is possible to define a function tmp that is only visible inside
>another function f?
See flet and labels in the Hyperspec.
>[...]
Kind regards,
Hannah.
> (1)
> Why does something like this not work:
> (setq f (lambda (x) (+ x 1)))
> (f 3)
>
> though the following line works:
> ((lambda (x) (+ x 1)) 1)
You're setting the "value binding" for the symbol f. If a
symbol is used in the first position of a list, the "function
binding" is used.
> (2)
> And it is possible to define a function tmp that is only visible inside
> another function f?
Check the hyperspec for "labels" and "flet". Briefly,
(defun f
(flet ((tmp (args for tmp) ...) ...)
(body of f)))
--
Raymond Wiker Mail: Raymon...@fast.no
Senior Software Engineer Web: http://www.fast.no/
Fast Search & Transfer ASA Phone: +47 23 01 11 60
P.O. Box 1677 Vika Fax: +47 35 54 87 99
NO-0120 Oslo, NORWAY Mob: +47 48 01 11 60
Try FAST Search: http://alltheweb.com/
CL-USER 194 > (setq f (lambda (x) (+ x 1)))
#'(LAMBDA (X) (+ X 1))
CL-USER 195 > (symbol-value 'f)
#'(LAMBDA (X) (+ X 1))
CL-USER 196 > (symbol-function 'f)
Error: Undefined function F in form (SYMBOL-FUNCTION F).
...
CL-USER 198 > (funcall (symbol-value 'f) 3)
4
CL-USER 199 > (setf (symbol-function 'f) (symbol-value 'f))
#'(LAMBDA (X) (+ X 1))
CL-USER 200 > (f 3)
4
Symbols have both a value slot and a function slot. (Symbols have more than
that, look in the CLHS.) That's at the heart of the Lisp-1 vs. Lisp-2
threads you see here from time to time.
I forgot to answer the second question.
(defun f (x)
(labels ((tmp (y)
(+ x y)))
(tmp (* 3 x))))
> (1)
> Why does something like this not work:
> (setq f (lambda (x) (+ x 1)))
> (f 3)
>
> though the following line works:
> ((lambda (x) (+ x 1)) 1)
As has already been pointed out, symbols in Lisp have several cells
associated with them. These are accessible via the SYMBOL- functions,
e.g., SYMBOL-VALUE, SYMBOL-PLIST, etc... You may have some exposure to
Scheme wherein a symbol has a single value rather than a value and
(potentially) a function as in Common Lisp. In that case what you are
trying to do would work as expected (I think...).
Typically we define a function using DEFUN:
(defun f1 (x) (+ x 1))
This is similar to the following:
(setf (symbol-function 'f1) #'(lambda (x) (+ x 1)))
In your example you assigned a value to F. When Lisp looked for a
function associated with F, it found none. FUNCALL can be used to invoke
a function such as the one you stored in F:
(funcall f 3) vs. (f1 3)
Thank you all for these answers. (I have not had any "exposure to Scheme",
I was simply trying to define a "local function".)
> Check the hyperspec for "labels" and "flet". Briefly,
>
> (defun f
> (flet ((tmp (args for tmp) ...) ...)
> (body of f)))
(defun f (args of f)
(flet ((tmp (args for tmp) ...) ...)
(body of f)))
--
~jrm
Aieee.... embarrassing. Even more embarrassing is that I spent
close to 30 seconds staring at your post, first wondering what the
difference was and then why _you_ omitted the arglist from the defun.
> Joe Marshall <prunes...@comcast.net> writes:
>
>> Raymond Wiker <Raymon...@fast.no> writes:
>>
>>> Check the hyperspec for "labels" and "flet". Briefly,
>>>
>>> (defun f
>>> (flet ((tmp (args for tmp) ...) ...)
>>> (body of f)))
>>
>>
>> (defun f (args of f)
>> (flet ((tmp (args for tmp) ...) ...)
>> (body of f)))
>
> Aieee.... embarrassing. Even more embarrassing is that I spent
> close to 30 seconds staring at your post, first wondering what the
> difference was and then why _you_ omitted the arglist from the defun.
Nothing like having another set of eyeballs to expose the most
embarrassing typos!
So this is where you are at, after three years of c.l.l participation?
> So this is where you are at, after three years of c.l.l participation?
Yes, because I always stop.
I decided at least five times to abandon the idea of using Lisp in
teaching completely. But again and again I start over again. There is some
strange fascination of Lisp that no other computer language has. This time
it happened that I was told in a German newsgroup to use Haskell in
teaching (I use Python at the moment). So I downloaded GHC, it even worked
this time as they have a windows installer now. But then, while reading
the a book about it (the one by Hudak, which is excellent by the way) I
started telling to myself: This is completely crazy and if I really want
to stress functional aspects of programming, which seems to be a good
thing to me, I should prefer Lisp or Scheme.
So I downloaded MIT Scheme but it turned out that it cannot be used on
Windows, at least it cannot be started in Emacs any more. (I asked in the
Scheme NG and additionally in the mailing list but received no sensible
answer. (Yes, I know DrScheme and maybe I shall use it...)
So I finally downloaded CLisp again... It would be absolutely phantastic
for teaching if only I could do a *little* graphics with it (on XP),
sigh... At least what can be done with MIT
Scheme: opening a graphical window and drawing lines, rectangles, etc.
You see: This is deeply tragic passion-love.
> On Wed, 17 Mar 2004 10:51:22 -0800, Kaz Kylheku wrote:
>
> > So this is where you are at, after three years of c.l.l participation?
>
> Yes, because I always stop.
>
> I decided at least five times to abandon the idea of using Lisp in
> teaching completely. But again and again I start over again. There is some
> strange fascination of Lisp that no other computer language has. This time
> it happened that I was told in a German newsgroup to use Haskell in
> teaching (I use Python at the moment). So I downloaded GHC, it even worked
> this time as they have a windows installer now. But then, while reading
> the a book about it (the one by Hudak, which is excellent by the way) I
> started telling to myself: This is completely crazy and if I really want
> to stress functional aspects of programming, which seems to be a good
> thing to me, I should prefer Lisp or Scheme.
>
> So I downloaded MIT Scheme but it turned out that it cannot be used on
> Windows, at least it cannot be started in Emacs any more. (I asked in the
> Scheme NG and additionally in the mailing list but received no sensible
> answer. (Yes, I know DrScheme and maybe I shall use it...)
>
> So I finally downloaded CLisp again... It would be absolutely phantastic
> for teaching if only I could do a *little* graphics with it (on XP),
> sigh... At least what can be done with MIT
> Scheme: opening a graphical window and drawing lines, rectangles, etc.
>
> You see: This is deeply tragic passion-love.
You should try DrScheme.
http://drscheme.org/
http://download.plt-scheme.org/drscheme/
--
__Pascal_Bourguignon__ http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/
> You should try DrScheme.
Thx, I have. But when the reference implementation does not work? What is
the reason for offering MIT Scheme for Windows if you cannot work with it
in a sensible manner?
I am going to use CLisp this time. I am planning to write a few very
simple functions that will draw the objects I want to. The function calls
will be immediately translated into Postsrcipt and saved on Disk. Then it
can be viewed and printed with Gsview.
But this is just a plan.
> On Thu, 18 Mar 2004 03:05:34 +0100, Pascal Bourguignon wrote:
>
> > You should try DrScheme.
>
> Thx, I have. But when the reference implementation does not work? What is
> the reason for offering MIT Scheme for Windows if you cannot work with it
> in a sensible manner?
Scheme, is defined no more than Common-Lisp by a reference implementation!
The reference for Scheme is the R5RS,
in which the last "R" means "Reference" !!
And anyway, perl, for example, does not run on CICS. (Or does it?)
That does not remove any of its qualities as a reference
implementation...
> I am going to use CLisp this time. I am planning to write a few very
> simple functions that will draw the objects I want to. The function calls
> will be immediately translated into Postsrcipt and saved on Disk. Then it
> can be viewed and printed with Gsview.
>
> But this is just a plan.
You could do better!
Why go thru the disk?
(let* ((win-w 512)
(win-h 342)
(win-back 0.33)
(but-x 10)
(but-y 140)
(but-w 76)
(but-h 20)
(but-back 0.66)
(but-title "Viva NeXT!")
(but-font "Helvetica")
(ps (ext:run-program "gs"
:arguments (list (format nil "-g~Dx~D" win-w win-h))
:input :stream)))
(format ps "newpath 0 0 moveto ~D 0 rlineto 0 ~D rlineto ~D 0 rlineto ~
closepath ~F setgray fill ~%"
win-w win-h (- win-w) win-back)
(format ps "newpath ~D ~D moveto ~D 0 rlineto 0 ~D rlineto ~D 0 rlineto ~
closepath ~F setgray fill ~%~
newpath ~D ~D moveto ~D 0 rlineto 0 ~D rlineto
1.00 setlinewidth ~
0.00 setgray stroke ~
newpath ~D ~D moveto 0 ~D rlineto ~D 0 rlineto
1.00 setgray stroke ~%"
but-x (- win-h but-y) but-w but-h (- but-w) but-back
but-x (- win-h but-y) but-w but-h
but-x (- win-h but-y) but-h but-w)
(format ps "0.00 setgray /~A findfont 12 scalefont setfont ~
~D ~D moveto (~A) show ~%"
but-font (+ but-x 6) (+ (- win-h but-y) 6) but-title)
(format ps "showpage~%")
(read-line) (format ps "~%quit~%"))
Of course, all this calls for intensive macrology...
R5RS is an abbreviation for Revised^5 Report on Scheme. Where do you
see "Reference"?
--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
Thank you very much! Should this program run "out of the box"? I get the
error message "gsview: Error parsing command line" (in a window of gsview).
TIA,
> In article <877jxik...@thalassa.informatimago.com>,
> Pascal Bourguignon <sp...@thalassa.informatimago.com> wrote:
> > Scheme, is defined no more than Common-Lisp by a reference implementation!
> >
> > The reference for Scheme is the R5RS,
> > in which the last "R" means "Reference" !!
>
> R5RS is an abbreviation for Revised^5 Report on Scheme. Where do you
> see "Reference"?
In my failing memory. Sorry.
> On Thu, 18 Mar 2004 06:43:27 +0100, Pascal Bourguignon wrote:
>
> > You could do better!
> > Why go thru the disk?
> >
> > (ps (ext:run-program "gs"
> > :arguments (list (format nil "-g~Dx~D" win-w win-h))
> > :input :stream)))
> >
> > Of course, all this calls for intensive macrology...
>
> Thank you very much! Should this program run "out of the box"? I get the
> error message "gsview: Error parsing command line" (in a window of gsview).
Well, obviously I don't have a MS-Windows system available with
gsview. It made it with ghostscript on unix. The opions and their
syntax may be different. You could try first without any
argument. The purpose of -g is to specify the size of the ghostscript
window.
> Well, obviously I don't have a MS-Windows system available with
> gsview. It made it with ghostscript on unix. The opions and their
> syntax may be different. You could try first without any
> argument. The purpose of -g is to specify the size of the ghostscript
> window.
Is it really necessary
to add so much extra whitespace?
Justified monospaced text is hard
to read, and you've added
even more space than is needed
for justification.
--
Gareth McCaughan
.sig under construc
1- ask it to the programmer of emacs full justify function.
2- I like it full justified.
3- your paragraph full justified looks like:
Is it really necessary to add so much extra whitespace? Justified
monospaced text is hard to read, and you've added even more space than
is needed for justification.
and is quite readable.
> > > Well, obviously I don't have a MS-Windows system available with
> > > gsview. It made it with ghostscript on unix. The opions and their
> > > syntax may be different. You could try first without any
> > > argument. The purpose of -g is to specify the size of the ghostscript
> > > window.
> >
> > Is it really necessary
> > to add so much extra whitespace?
> > Justified monospaced text is hard
> > to read, and you've added
> > even more space than is needed
> > for justification.
>
> 1- ask it to the programmer of emacs full justify function.
> 2- I like it full justified.
> 3- your paragraph full justified looks like:
>
> Is it really necessary to add so much extra whitespace? Justified
> monospaced text is hard to read, and you've added even more space than
> is needed for justification.
>
> and is quite readable.
1. It's no affair of mine what tools you use to get your articles
to look the way they do.
2. I find your articles consistently hard to read simply because
they have uneven spacing because of full justification. Of course
you must do as you like.
3. I was exaggerating for effect. I apologize if that wasn't
obvious.
> I find your articles consistently hard to read simply because they
> have uneven spacing because of full justification.
<AOL>
Me too.
</AOL>
Ok. Since I don't see much full justified text from others, I won't
bother calling a vote on this and I'll try to shift my finger ten
millimeters and hit F5 instead if F6 to justify text for newsgroup.
But I'll continue to full justify my texts for my eyes, nah!
> 3- your paragraph full justified looks like:
> and is quite readable.
The problem is with long paragraphs. No with short ones.
When the lines have uneven lengths I find it easier to find
the next line.
I might be biased though - I don't like even margins in boks
either.
--
Jens Axel Søgaard
I do not know if this works on Windows at all.
If I write ":arguments ()" instead of your arguments (and I vaguely
remember that I do not have to quote the empty list), then gsview opens
without a file.
If test.ps is a valid ps file and I say (at the command line)
gsview < test.ps,
gsview will open but the drawing in test.ps is not shown. This is what
ext:run-program dows, if I understand this correctly.
But if I say
gsview < test.ps,
the drawing is shown.
Anyway, I am getting convinced that clisp is the right tool for me as I
only needed *some* capability of displaying drawings and Postscript is
definitely powerful enough for our needs :)
Having to creat a named file on disk is not much of an inconvenience and
if want to do this, I can even make that transparent to my pupils.
Your suggestion were very helpful however, as now I know how to run
external programs.
One further question: I saw, there is support for sockets built into
CLisp. Can I then connect to a news server like text-west.newsfeeds.com
using nntp?
> On Thu, 18 Mar 2004 22:47:13 +0100, Pascal Bourguignon wrote:
> > Well, obviously I don't have a MS-Windows system available with
> > gsview. It made it with ghostscript on unix. The opions and their
> > syntax may be different. You could try first without any
> > argument. The purpose of -g is to specify the size of the ghostscript
> > window.
>
> I do not know if this works on Windows at all.
> If I write ":arguments ()" instead of your arguments (and I vaguely
> remember that I do not have to quote the empty list), then gsview opens
> without a file.
Yes, that's the point. Don't you have pipes on MS-Windows?
> If test.ps is a valid ps file and I say (at the command line)
> gsview < test.ps,
> gsview will open but the drawing in test.ps is not shown. This is what
> ext:run-program dows, if I understand this correctly.
> But if I say
> gsview < test.ps,
> the drawing is shown.
>
> Anyway, I am getting convinced that clisp is the right tool for me as I
> only needed *some* capability of displaying drawings and Postscript is
> definitely powerful enough for our needs :)
> Having to creat a named file on disk is not much of an inconvenience and
> if want to do this, I can even make that transparent to my pupils.
The advantage of using a pipe is to get the poscript code displayed as
soon as it's written by the lisp code. You can easily test and debug
your postscript generating lisp code.
> Your suggestion were very helpful however, as now I know how to run
> external programs.
>
> One further question: I saw, there is support for sockets built into
> CLisp. Can I then connect to a news server like text-west.newsfeeds.com
> using nntp?
You can write a NNTP client in clisp yes.
http://www.cliki.net/admin/search?words=nntp
You can still drop three spaces from each line above:
-re-justified quote starts
Ok. Since I don't see much full justified text from others, I won't
bother calling a vote on this and I'll try to shift my finger ten
millimeters and hit F5 instead if F6 to justify text for newsgroup.
But I'll continue to full justify my texts for my eyes, nah!
-quote ends
(PS, I don't mind either way.)
"Idiosyncratic indentations, double-spacing, capitalization, etc., while
stamps of individuality, leave one an easy target for parody."
-- from the Symbolics Guidelines for Sending Mail