Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion trouble learning LISP
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
 
Pascal Bourguignon  
View profile  
 More options Oct 16 2006, 10:12 pm
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <p...@informatimago.com>
Date: Tue, 17 Oct 2006 04:12:16 +0200
Local: Mon, Oct 16 2006 10:12 pm
Subject: Re: trouble learning LISP

"dlarkin" <dlark...@mail.gatech.edu> writes:
> Can an IF statement in lisp execute multiple expressions if it tests false.

No it cannot.

> For example:

> (if (null expression) nil     ;;if nil then skip the else part
>     ((expression1)            ;; else do expression 1 and expression 2
>     (expression2))

This is meaningless in Common Lisp.

If you want to program in lisp, why don't you just read some lisp
tutorial instead of trying to invent some funny syntax?

If you want to do expression1 and expression2 only when expression is
not nil, why don't you just say so?

(when expression
   expression1
   expression2)

If you don't want to do expression1 and expressions unless expression
is nil, why don't you just say so?

(unless (null expression)
   expression1
   expression2)

Also, if you want the two branches of a IF, you have the same problem
than in Pascal, and the same solution.  Only, a BEGIN ... END block is
written (PROGN ...) in lisp.

(if condition
    (progn
        ...)
    (progn
        ...))

But most often, you don't need to use progn, because you'll be using a
let or some other form that takes several expressions as body.

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

"This statement is false."            In Lisp: (defun Q () (eq nil (Q)))


    Reply to author    Forward  
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.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google