From: anders
Subject: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178185326.909587.152140@o5g2000hsb.googlegroups.com>
Hello, i am stumbling to learn LISP
i have set upp EMACS and SLIME running CLISP att the backend

Now i try to print stuff i have test diffrent stuff and last was

(defun main ()
     (format t "Hello World ~%")
)

When a test by enter (main)

it say
Hello world
NIL

Way and can i some way get rid of this NIL stuff

From: Matthias Benkard
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178186064.667839.281620@h2g2000hsg.googlegroups.com>
Hi,


> (defun main ()
>      (format t "Hello World ~%")
> )

That's unlispy formatting. Better write this:

(defun main ()
  (format t "Hello World ~%"))


> it say
> Hello world
> NIL

If what you mean by �it� is your Lisp program, you're wrong: �It�
doesn't print NIL. That's just the return value of the expression that
you typed in. SLIME always tells you the return value of expressions,
but that's a SLIME feature, it's nothing to do with Lisp itself.

If you really want a function to return no value at all rather than
NIL, you can use (VALUES) for that, but that's just a style issue that
has little effect on the semantics of your program.

Bye-bye,
Matthias
From: Pascal Bourguignon
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <877irnah17.fsf@thalassa.lan.informatimago.com>
Matthias Benkard <··········@gmail.com> writes:

> Hi,
>
>
>> (defun main ()
>>      (format t "Hello World ~%")
>> )
>
> That's unlispy formatting. Better write this:
>
> (defun main ()
>   (format t "Hello World ~%"))
>
>
>> it say
>> Hello world
>> NIL
>
> If what you mean by �it� is your Lisp program, you're wrong: �It�
> doesn't print NIL. That's just the return value of the expression that
> you typed in. SLIME always tells you the return value of expressions,
> but that's a SLIME feature, it's nothing to do with Lisp itself.
>
> If you really want a function to return no value at all rather than
> NIL, you can use (VALUES) for that, but that's just a style issue that
> has little effect on the semantics of your program.

But it might be worse.  What is printed by the REPL when no value is
returned is not specified.  You might as well get:

SOMEIMPL> (defun main ()
              (format t "Hello World ~%")
              (values))
MAIN
SOMEIMPL> (main)
Hello world
THIS EXPRESSION RETURNED ABSOLUTELY, DEFINITELY NO VALUE. REALLY.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.
From: Matthias Benkard
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178450360.529851.213670@p77g2000hsh.googlegroups.com>
Hi,

> But it might be worse.  What is printed by the REPL when no value is
> returned is not specified.  You might as well get ...
>
> SOMEIMPL> (main)
> Hello world
> THIS EXPRESSION RETURNED ABSOLUTELY, DEFINITELY NO VALUE. REALLY.

Right.  SLIME actually does something not unlike that:

CL-USER> (values)
; No value

Bye,
Matthias
From: fireblade
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178189032.058576.72850@e65g2000hsc.googlegroups.com>
On May 3, 11:42 am, anders <················@gmail.com> wrote:
> Hello, i am stumbling to learn LISP
> i have set upp EMACS and SLIME running CLISP att the backend
>
> Now i try to print stuff i have test diffrent stuff and last was
>
> (defun main ()
>      (format t "Hello World ~%")
> )
>
> When a test by enter (main)
>
> it say
> Hello world
> NIL
>
> Way and can i some way get rid of this NIL stuff

First get use to proper lisp formatting like:
(defun main ()
   (format t "Hello World ~%"))
Second :
  The nil you see at REPL is actually result of evaluating main
function, main prints Hello world  as side effect and returns nil as a
result.  There 's nothing wrong with your code if make an exe of it
it'll just print Hello world without nil.

cheers
bobi
From: ·············@hotmail.com
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178193704.434219.242790@e65g2000hsc.googlegroups.com>
On May 3, 11:42 am, anders <················@gmail.com> wrote:
> Hello, i am stumbling to learn LISP
> i have set upp EMACS and SLIME running CLISP att the backend
>
> Now i try to print stuff i have test diffrent stuff and last was
>
> (defun main ()
>      (format t "Hello World ~%")
> )
>
> When a test by enter (main)
>
> it say
> Hello world
> NIL
>
> Way and can i some way get rid of this NIL stuff

Working with Practical Common Lisp will give you a better look at lisp
language instead of doing c with lisp, especially if you're not newbie
to programming.The book is free in pdf, though I would recommend
buying printed edition.

Antoan
From: Dan Bensen
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <f1cfqp$kgs$1@wildfire.prairienet.org>
anders wrote:
> (defun main ()
>      (format t "Hello World ~%")
> )

> Hello world
> NIL

> Way and can i some way get rid of this NIL stuff

If you're on Linux or Unix, make this the first line
of your program:
#!/usr/local/bin/clisp --quiet

Then make your program executable:
$ chmod +x my_program.l

and run your program on the command line:
$ my_program.l
Hello world

-- 
Dan
www.prairienet.org/~dsb/
From: anders
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178190715.666393.56140@c35g2000hsg.googlegroups.com>
Tanks everyone, and i promisse to learn indent like LISP use it.
// Anders
From: fireblade
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <1178191065.484980.118510@n76g2000hsh.googlegroups.com>
On May 3, 1:11 pm, anders <················@gmail.com> wrote:
> Tanks everyone, and i promisse to learn indent like LISP use it.
> // Anders

You don't have to. Your editor like Emacs or whatever will do it for
you
just learn to use it.
From: Kent M Pitman
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <u1whyj63y.fsf@nhplace.com>
anders <················@gmail.com> writes:

> Hello, i am stumbling to learn LISP
> i have set upp EMACS and SLIME running CLISP att the backend
> 
> Now i try to print stuff i have test diffrent stuff and last was
> 
> (defun main ()
>      (format t "Hello World ~%")
> )
> 
> When a test by enter (main)
> 
> it say
> Hello world
> NIL
> 
> Way and can i some way get rid of this NIL stuff

The right way to think of the question you've asked is this to ponder
this paraphrase of your question:

  I want to use echo, but I keep seeing C:\>
  Is there some way to get rid of it?

     C:\> echo foo
     foo
     C:\> 

The problem you're having is that the NIL is printed out after your
program exits.

In general, the deep philosophical issue is that it is hard to control
the effect of things that happen after you yield control.

It's easy to see what is "after your program" in the shell script case,
because you know what the shell is and what your program is.  In Lisp,
you're not familiar with looking at what parts it prints, so you're 
confusing what the Lisp is doing and what your program is doing.

The NIL corresponds to the 0 in the following hypothetical alternate
shell output:

 C:\> echo foo
 foo
 0
 C:\>

where the zero was not your program doing something, but rather the shell
reporting what the returned error code was from the prior command.

Whether or not such a feature is shown is a property of the shell, not
of the shell language.  Likewise in Lisp, it's a property of your vendor's
IDE, not of CL, whether the functions you type interactively show their
return values, and how.
From: Pascal Bourguignon
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <873b2bagv3.fsf@thalassa.lan.informatimago.com>
Kent M Pitman <······@nhplace.com> writes:

> anders <················@gmail.com> writes:
>
>> Hello, i am stumbling to learn LISP
>> i have set upp EMACS and SLIME running CLISP att the backend
>> 
>> Now i try to print stuff i have test diffrent stuff and last was
>> 
>> (defun main ()
>>      (format t "Hello World ~%")
>> )
>> 
>> When a test by enter (main)
>> 
>> it say
>> Hello world
>> NIL
>> 
>> Way and can i some way get rid of this NIL stuff
>
> The right way to think of the question you've asked is this to ponder
> this paraphrase of your question:
>
>   I want to use echo, but I keep seeing C:\>
>   Is there some way to get rid of it?
>
>      C:\> echo foo
>      foo
>      C:\> 
>
> The problem you're having is that the NIL is printed out after your
> program exits.
> [...]
> Whether or not such a feature is shown is a property of the shell, not
> of the shell language.  Likewise in Lisp, it's a property of your vendor's
> IDE, not of CL, whether the functions you type interactively show their
> return values, and how.

Well, there is still a direct answer to the question asked:

(defmacro handling-errors (&body body)
  `(HANDLER-CASE (progn ,@body)
     (simple-condition 
         (ERR) 
       (format *error-output* "~&~A: ~%" (class-name (class-of err)))
       (apply (function format) *error-output*
              (simple-condition-format-control   err)
              (simple-condition-format-arguments err))
       (format *error-output* "~&")
       (finish-output))
     (condition 
         (ERR) 
       (format *error-output* "~&~A: ~%  ~S~%"
               (class-name (class-of err)) err)
       (finish-output))))


(defun no-result-repl ()
  (do ((+eof+ (gensym))
       (hist 1 (1+ hist)))
      (nil)
    (format t "~%~A[~D]> " (package-name *package*) hist)
    (finish-output)
    (handling-errors
     (setf - (read *standard-input* nil +eof+))
     (when (or (eq - +eof+)
               (member - '((quit)(exit)(continue)) :test (function equal)))
       (return-from no-result-repl))
     (let ((results (multiple-value-list (eval -))))
       (shiftf +++ ++ + -)
       (shiftf /// // / results)
       (shiftf *** ** * (first /))))))



C/USER[3]> (NO-RESULT-REPL)

COMMON-LISP-USER[1]> (defun main ()
                       (format t "Hello World ~%"))

COMMON-LISP-USER[2]> (main)
Hello World 

COMMON-LISP-USER[3]> (+ 1 2)

COMMON-LISP-USER[4]> (print *)

3 
COMMON-LISP-USER[5]> (quit)

NIL
C/USER[4]> 

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.
From: Rainer Joswig
Subject: Re: How to print result nice in LISP without the nil att end
Date: 
Message-ID: <joswig-6F2016.11512203052007@news-europe.giganews.com>
In article <························@o5g2000hsb.googlegroups.com>,
 anders <················@gmail.com> wrote:

> Hello, i am stumbling to learn LISP

Start unlearning.

> i have set upp EMACS and SLIME running CLISP att the backend
> 
> Now i try to print stuff i have test diffrent stuff and last was
> 
> (defun main ()
>      (format t "Hello World ~%")
> )
> 
> When a test by enter (main)
> 
> it say
> Hello world
> NIL
> 
> Way and can i some way get rid of this NIL stuff


Well, try this:

(defun main ()
     (format t "Hello World ~%")
     t
)

What will it do now?

Then try this:

(defun main ()
     (format t "Hello World ~%")
     (format t "I promise to indent like Lisp likes it ~%")
     t
)

There are two lines printed and ...?


How do you learn Lisp? Do you have a good book or
tutorial?

-- 
http://lispm.dyndns.org