LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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: 17

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,786

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
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
 
2 members found this post helpful.
Old 08-11-2021, 06:06 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,150

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
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: 10,683
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
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,918

Rep: Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035Reputation: 5035
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.
 
Old 01-09-2022, 12:02 AM   #6
slac-in-the-box
Member
 
Registered: Mar 2010
Location: oregon
Distribution: slackware64-15.0 / slarm64-current
Posts: 780
Blog Entries: 1

Rep: Reputation: 432Reputation: 432Reputation: 432Reputation: 432Reputation: 432
Quote:
Originally Posted by syg00 View Post
With a new language seemingly appearing every other month, lisp still has (new) adherents ????.
Memories from the 70s struggle to emerge...
The new languages, imho, haven't improved computer science -- mostly just vanity (see I made a programming language, too), or economic power trips (we'll make our own language for our platform, and when developers use our language, it will advance our platform) This doesn't advance computer science, but rather obfuscates it by making it less homogenous for no reason other than vanity and greed.

Way to see through the crud, Petr Strajt: welcome to secret alien technology!
 
2 members found this post helpful.
Old 01-09-2022, 02:34 AM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,150

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Yabbut - is it going to get the OP a job ?.

When I graduated, I had to move state to get a job because I hadn't taken the optional COBOL units (it was a while ago). Nobody gave a damn about the nicities of compsci - they wanted people who could help the business run the business that made them money.
Dunno what the job market is these days tho'.
 
Old 01-09-2022, 05:30 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,027

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
is this then or than ?
 
Old 01-10-2022, 12:05 AM   #9
slac-in-the-box
Member
 
Registered: Mar 2010
Location: oregon
Distribution: slackware64-15.0 / slarm64-current
Posts: 780
Blog Entries: 1

Rep: Reputation: 432Reputation: 432Reputation: 432Reputation: 432Reputation: 432
Quote:
Originally Posted by syg00 View Post
Yabbut - is it going to get the OP a job ?.
...
Dunno what the job market is these days tho'.
Yes, there are common lisp jobs -- often one must search for functional programming... and common lisp has bindings to so many other languages, that you can take, for example, a job building qt widgets, and use commonqt/smoke to create the widgets... good employers don't care how you do it as long as you do it. The job title might not say lisp or functional programming, but instead say qt. There's heaps of medical statistics jobs these days, mostly using R. But common lisp has you covered with bindings to R as well.

Of course, you have to want a job in the first place...
 
Old 01-11-2022, 02:13 PM   #10
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,683
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
and(
((an))()(((interesting)))(question)
if(
so((do)(not)(((expect (to be))))(life(the of(the(party))


No. I have no idea if the parentheses match.
 
Old 01-11-2022, 02:57 PM   #11
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,678

Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
is this then or than ?
Neither. See the explanation by ntubski in #2.
 
Old 01-13-2022, 12:26 PM   #12
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,683
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
I remember seeing a visual interface to the LISP programming language which simply presented the inherent list/node structure of a program in a graphical way. You could open the program with it, change it visually, and then save it. IIRC, it also had the ability to recognize syntax errors. Unfortunately, I no longer remember what it was called. (AutoCAD has something called "Visual LISP" which is not the same thing.)

One thing's quite sure, though: "LISP will never die." Possibly the very-earliest language ever invented.
 
Old 06-26-2022, 12:21 AM   #13
0++
LQ Newbie
 
Registered: Mar 2010
Distribution: Manjaro, Slackware, Debian Sid, Kali, openSUSE TW
Posts: 23

Rep: Reputation: 2
i havent logged in, in so long and finally i did and noticed a LISP! question , and on a not too ancient thread either, well if incase someone sees this i'll leave my own 2 cents here

Quote:
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".
or you can just use string-equal since that is case insensitive that way you can accept both cases of y or Y without resorting to a cond or a nested if, for more concise code,

then use
Quote:
(uiop:run-program "firefox") /or (uiop:run-program (list "firefox" "http:url"))
to run firefox with an optional specific url in mind.

TIP: also dont get used to setq just use setf when mutating bindings

you can also write your code by defining a function instead and just using let for variable declaration, for ex:

Quote:
(defun run-firefox-run ()
(write-line "Do you want to run Firefox? y/n")
(let ((answer (read))
...etc-etc))
P.S. I'd also like to suggest for beginners interested in learning Lisp, to try to use Racket first instead of Common Lisp, its just easier to get set up in the beginning, super easy brain dead simple install, and Racket comes with an IDE thats easy to use right at the start so you dont get overwhelmed and learn without much distraction unlike starting with Common Lisp theres plenty much to learn and configure before you get going which detracts from the learning, then after you can switch to Common Lisp, when you get your bearings, if you still want to that is, as Racket is plenty capable as a Lisp(but as a Scheme derivative Lisp dialect with batteries included), but hey Common Lisp Rocks too, you cant beat SLIME on EMACS

Last edited by 0++; 06-26-2022 at 12:53 AM. Reason: cant seem to fix the indentation of the code oh well
 
2 members found this post helpful.
Old 06-26-2022, 01:02 AM   #14
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,150

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
0++, use [code] rather than [quote] tags.
 
  


Reply



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 04:26 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