LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2021, 04:07 PM   #1
Petr Strajt
LQ Newbie
 
Registered: Oct 2011
Location: Olomouc Czech Republic
Distribution: Slackware
Posts: 12

Rep: Reputation: Disabled
Common Lisp beginer If else


Hi everybody,

I am beginer in Common Lisp. I am trying to create a code that asks the user if he wants to run firefox browser with y/n answer.

I have this code

Code:
(print"Do you want to run  Firefox? y/n")
(setq answer(read))
(if (= answer "y"))
    (run-program "firefox")
  than
  (/= answer y)
  (print "something")
If I run this code I receive this error message: *** - EVAL: too few parameters for special operator IF: (IF (= ANSWER "y"))

How to resolve this issue? Thank you for your advice
 
Old 08-11-2021, 05:18 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,612

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
Auto-indent the code in your editor (if your editor doesn't support that, find one that does). You will get this:
Code:
(if (= answer "y"))
(run-program "firefox")
than
(/= answer y)
(print "something")
Which is obviously wrong, the culprit is an extra close paren on the first line (I highlighted it). Also, the the general structure of an if form looks like this:

Code:
(if <TEST>
    <THEN>
  <ELSE>)
There are no keywords apart from the "if" itself, and you don't need to repeat/reverse the test.

See Common Lisp the Language, 2nd Edition - 7.6. Conditionals
 
1 members found this post helpful.
Old 08-11-2021, 06:06 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,922

Rep: Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628Reputation: 3628
With a new language seemingly appearing every other month, lisp still has (new) adherents ????.
Memories from the 70s struggle to emerge...
 
1 members found this post helpful.
Old 08-11-2021, 06:40 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,291
Blog Entries: 4

Rep: Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318Reputation: 3318
Yes, syg, people still enjoy working with "Lots of Irritating Silly Parentheses!"
 
Old 08-12-2021, 04:30 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,047

Rep: Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074Reputation: 4074
Use 'string=' rather than '=' for the comparison, or you'll likely get a "Not a Number" error. Also, read will likely uppercase the input unless you take steps to prevent it (google readtable-case), so you need to compare with "Y" not "y".

And yeah, an editor that does parenthesis matching/highlighting is a must have when you're doing lisp, otherwise you'll go insane.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Lisp Coding Bounty (get a copy of Land of Lisp) LXer Syndicated Linux News 0 10-23-2011 06:41 PM
Programming Ideas in Common Lisp Trizon Programming 1 03-03-2008 02:07 PM
Common Lisp stand alone question Trizon Programming 5 05-23-2007 09:07 AM
LISP or COMON LISP Compiler for Debian carspidey Programming 3 04-19-2006 07:46 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 06:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration