[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Variables

gengyangcai

11/12/2015 6:11:00 AM

This is an interesting function :

(defun ask-number ()
(format t "Please enter a number. ")
(let ((val (read)))
(if (numberp val) val
(ask-number))))

> (ask-number)
Please enter a number. a
Please enter a number. (ho hum)
Please enter a number. 52
52
8 Answers

Pascal J. Bourguignon

11/12/2015 7:40:00 AM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> This is an interesting function :
>
> (defun ask-number ()
> (format t "Please enter a number. ")
> (let ((val (read)))
> (if (numberp val) val
> (ask-number))))
>
>> (ask-number)
> Please enter a number. a
> Please enter a number. (ho hum)
> Please enter a number. 52
> 52

It's nice but it'd be better to use *query-io* for interactive I/O and
to flush the buffers!

(defun ask-number ()
(format *query-io* "~&Please enter a number: ")
(finish-output *query-io*)
(clear-input *query-io*)
(let ((val (read *query-io*)))
(if (numberp val)
val
(ask-number))))


user1> (ask-number)
Please enter a number: #c(1 2)

#C(1 2)
user1>

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

William James

11/12/2015 11:31:00 AM

0

Pascal J. Bourguignon wrote:

> CAI GENGYANG <gengyangcai@gmail.com> writes:
>
> > This is an interesting function :
> >
> > (defun ask-number ()
> > (format t "Please enter a number. ")
> > (let ((val (read)))
> > (if (numberp val) val
> > (ask-number))))
> >
> >> (ask-number)
> > Please enter a number. a
> > Please enter a number. (ho hum)
> > Please enter a number. 52
> > 52
>
> It's nice but it'd be better to use *query-io* for interactive I/O and
> to flush the buffers!
>
> (defun ask-number ()
> (format *query-io* "~&Please enter a number: ")
> (finish-output *query-io*)
> (clear-input *query-io*)
> (let ((val (read *query-io*)))
> (if (numberp val)
> val
> (ask-number))))
>
>
> user1> (ask-number)
> Please enter a number: #c(1 2)
>
> #C(1 2)
> user1>

MatzLisp (Ruby):

def ask_number
print "Enter a number: "
Float(gets)
rescue
ask_number
end

ask_number
Enter a number: hi
Enter a number: yes
Enter a number: 999_888
==>999888.0

--
Elie [Wiesel] thus could have remained at Birkenau to await the Russians.
Although his father had permission to stay with him as a hospital patient or
orderly, father and son talked it over and decided to move out with the
Germans. --- Robert Faurisson

Barry Margolin

11/12/2015 3:52:00 PM

0

In article <b9450f86-6712-4f6a-b920-a8e7348743cd@googlegroups.com>,
CAI GENGYANG <gengyangcai@gmail.com> wrote:

> This is an interesting function :

Seems incredibly boring to me. What's interesting about it?

>
> (defun ask-number ()
> (format t "Please enter a number. ")
> (let ((val (read)))
> (if (numberp val) val
> (ask-number))))
>
> > (ask-number)
> Please enter a number. a
> Please enter a number. (ho hum)
> Please enter a number. 52
> 52

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

gengyangcai

11/12/2015 5:21:00 PM

0

It just looks neat to me. Lisp has a bizarre syntax full of parentheses , but it is oddly simple and elegant ...



On Thursday, November 12, 2015 at 11:52:19 PM UTC+8, Barry Margolin wrote:
> In article <b9450f86-6712-4f6a-b920-a8e7348743cd@googlegroups.com>,
> CAI GENGYANG <gengyangcai@gmail.com> wrote:
>
> > This is an interesting function :
>
> Seems incredibly boring to me. What's interesting about it?
>
> >
> > (defun ask-number ()
> > (format t "Please enter a number. ")
> > (let ((val (read)))
> > (if (numberp val) val
> > (ask-number))))
> >
> > > (ask-number)
> > Please enter a number. a
> > Please enter a number. (ho hum)
> > Please enter a number. 52
> > 52
>
> --
> Barry Margolin, barmar@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***

swflint

11/12/2015 5:41:00 PM

0

Do I dare feed the troll?

>>>>> CAI GENGYANG writes:

CG> It just looks neat to me. Lisp has a bizarre syntax full of
CG> parentheses , but it is oddly simple and elegant ...

Why do you say lisp has a bizarre syntax? You seem to be asking such
simple questions that make it seem like you shouldn't have anything to
compare it to.

Yes, it is simple and elegant, but not oddly so.

CG> On Thursday, November 12, 2015 at 11:52:19 PM UTC+8, Barry Margolin wrote:
>> In article <b9450f86-6712-4f6a-b920-a8e7348743cd@googlegroups.com>,
>> CAI GENGYANG <gengyangcai@gmail.com> wrote:
>>
>> > This is an interesting function :
>>
>> Seems incredibly boring to me. What's interesting about it?
>>
>> > > (defun ask-number () > (format t "Please enter a number. ") >
>> (let ((val (read))) > (if (numberp val) val > (ask-number)))) > > >
>> (ask-number) > Please enter a number. a > Please enter a number. (ho
>> hum) > Please enter a number. 52 > 52
>>
>> -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post
>> questions in newsgroups, not directly to me ***

--
Samuel W. Flint
4096R/266596F4
(9477 D23E 389E 40C5 2F10 DE19 68E5 318E 2665 96F4)
(λs.s s) λs.s s

Kaz Kylheku

11/12/2015 7:06:00 PM

0

On 2015-11-12, CAI GENGYANG <gengyangcai@gmail.com> wrote:
> It just looks neat to me. Lisp has a bizarre syntax full of parentheses , but
> it is oddly simple and elegant ...

It appears that now that you've actually entered a complete function into your
Lisp system which executed correctly, you're promoting yourself from
"programmer", to "programming language critic".

Pascal J. Bourguignon

11/13/2015 9:30:00 AM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> It just looks neat to me. Lisp has a bizarre syntax full of
> parentheses , but it is oddly simple and elegant ...

What are you talking about? There's exactly the same number of
parenthesis in C for this small program. And then, the C program
doesn't do what the lisp program does, if we were to implement the exact
same features, we'd explode the number of parentheses in C.


[pjb@kuiper :0.0 spl]$ /tmp/a.sh

Lisp:
(()()(((()))(()())))
C:
(){(){(())(()){()}}}

[pjb@kuiper :0.0 spl]$ cat /tmp/a.sh
#!/bin/bash

printf "\nLisp:\n"
tr -d '[\055"_*=.,; A-Za-z0-9\n]' <<EOF
(defun ask-number ()
(format t "Please enter a number. ")
(let ((val (read)))
(if (numberp val) val
(ask-number))))
EOF
printf "\nC:\n"
tr -d '[\055"_*=.,; A-Za-z0-9\n]' <<EOF
char* ask_number(){
printf("Please enter a number. ");
{char buffer[80];
char* var=fgets(buffer,sizeof(buffer)-1,stdin);
if(numberp(val)){
return val;
ask_number();}}}

EOF
printf "\n"
[pjb@kuiper :0.0 spl]$



--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Richard Fateman

11/13/2015 3:58:00 PM

0

To Cai

Is it because Lisp has a bizarre syntax full of parentheses but it
is oddly simple and elegant that you wrote to comp.lang.lisp ?

says the doctor.:)