LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 01-30-2010, 04:43 AM   #1
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Rep: Reputation: 50
Lisp: beginner, how to represent "objects"


So, I'm learning Lisp, so I'd like to launch into it and learn it by writing a card game.

I come from a Java background, so I don't want to write "Java in Lisp" so...

I understand that Lisp is all about list processing, so lists are important to understand.

OK: is this a good way to represent a playing card in Lisp?

(card cons(suit cons(number cons(image)))) = card

or am I completely barking up the wrong tree?

titanium_geek
 
Old 01-30-2010, 09:56 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by titanium_geek View Post
So, I'm learning Lisp, so I'd like to launch into it and learn it by writing a card game.

I come from a Java background, so I don't want to write "Java in Lisp" so...

I understand that Lisp is all about list processing, so lists are important to understand.

OK: is this a good way to represent a playing card in Lisp?

(card cons(suit cons(number cons(image)))) = card

or am I completely barking up the wrong tree?

titanium_geek
CLOS: http://en.wikipedia.org/wiki/Common_Lisp_Object_System .
 
Old 01-30-2010, 09:59 PM   #3
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
Cheers, sometimes you just need someone to point you to the start of the trail. Now I've got some reading to do.

TG
 
Old 01-31-2010, 12:59 AM   #4
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
I found
Pascal Costanza's Highly Opinionated Guide to Lisp: http://p-cos.net/lisp/guide.html

Which seems to be a good intro also.

TG
 
Old 01-31-2010, 03:31 PM   #5
ozanbaba
Member
 
Registered: May 2003
Location: Tengiz
Distribution: Slackware64 13.37
Posts: 666

Rep: Reputation: 91
Quote:
Originally Posted by titanium_geek View Post
I found
Pascal Costanza's Highly Opinionated Guide to Lisp: http://p-cos.net/lisp/guide.html

Which seems to be a good intro also.

TG
don't run too fast, lisp is propaply most different programing language you may come around. it's different, very different from java, c, c++ etc. Python has some similarities, javascript, too. in the end lisp has completely different philosophy behind it. i found Lisp by Winston, Patrick Henry very helpful when i learned lisp.


my biggest advice would be take it slow. don't jump to CLOS right away. take your time understand main lisp ideas. it will take some time (it ate my one bloody semester. i failed a lot of classes that semester ), when you do, CLOS will come easy.
 
Old 01-31-2010, 04:49 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by ozanbaba View Post
don't run too fast, lisp is propaply most different programing language you may come around. it's different, very different from java, c, c++ etc. Python has some similarities, javascript, too. in the end lisp has completely different philosophy behind it. i found Lisp by Winston, Patrick Henry very helpful when i learned lisp.


my biggest advice would be take it slow. don't jump to CLOS right away. take your time understand main lisp ideas. it will take some time (it ate my one bloody semester. i failed a lot of classes that semester ), when you do, CLOS will come easy.
I would word it stronger - jumping on OO wagon too early may deprive the learner from the chance to realize that in functional languages many OO complexities/annoyances are not needed in the first place.
 
Old 01-31-2010, 04:56 PM   #7
ozanbaba
Member
 
Registered: May 2003
Location: Tengiz
Distribution: Slackware64 13.37
Posts: 666

Rep: Reputation: 91
Quote:
Originally Posted by Sergei Steshenko View Post
I would word it stronger - jumping on OO wagon too early may deprive the learner from the chance to realize that in functional languages many OO complexities/annoyances are not needed in the first place.
i didn't want to scare a possible future lisp programmer. by the way, you know you can do OO with only function
 
Old 01-31-2010, 05:21 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by ozanbaba View Post
i didn't want to scare a possible future lisp programmer. by the way, you know you can do OO with only function
I more and more prefer functional and have never been a big fan of OO. I think it is proven mathematically that OO can be implemented through functional, and I think I once found an article explaining this in detail.
 
Old 01-31-2010, 05:31 PM   #9
ozanbaba
Member
 
Registered: May 2003
Location: Tengiz
Distribution: Slackware64 13.37
Posts: 666

Rep: Reputation: 91
Quote:
Originally Posted by Sergei Steshenko View Post
I more and more prefer functional and have never been a big fan of OO. I think it is proven mathematically that OO can be implemented through functional, and I think I once found an article explaining this in detail.
well there's good old UNIX VFS
 
Old 01-31-2010, 09:45 PM   #10
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
so, back to my original question. I would like to program a very simple card game. I'm hesitant to describe it because in the past answers to my questions here have been "here is the whole code" which is very discouraging when you're trying to do it yourself.

OK: so ignoring objects and CLOS, what is the best mechanism for representing a "thing" in lisp? Should I use a list?
I want a deck of cards, basically. Then I can work out what to do with them later. Is this approach: http://code.tumyr.org/lisp/poker/cards.lisp a decent one?

(Note to self: "card in lisp" is a google search with many non-relevant results, "deck of cards in lisp" is a better search string.)

I found lisperati an interesting read- and am considering the text-adventure: could be fun.


I want to program a game in Lisp that uses extremely simple AI to give me a chance at not hyper-ventilating over my AI pracs (in lisp) next semester.

thanks for the replies so far everyone.
TG
 
Old 01-31-2010, 09:59 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by titanium_geek View Post
...
OK: so ignoring objects and CLOS, what is the best mechanism for representing a "thing" in lisp? Should I use a list?[/i]
...
TG
I myself am very new to LISP, but from experience with Perl I can tell you that objects are best represented as scopes into which interrelated datum and functions are encapsulated, with, as necessary, usage of closures.

Regarding data representation - look at 'cond' construct too - to me it looks kind of like hash in Perl (in a sense), i.e. if I understand correctly, it is possible to imitate access to hash table using "key" as input and getting its "value" as output. Probably LISP macro mechanism can be used to add "key" "value" pairs.

The above paragraph is just my interpretation of possible usage. I took a look at http://www.apl.jhu.edu/~hall/Lisp-No...sp-Overview.ps - just one page .
 
Old 01-31-2010, 10:56 PM   #12
titanium_geek
Senior Member
 
Registered: May 2002
Location: Melbourne Australia
Distribution: it died/ macosx
Posts: 2,478

Original Poster
Rep: Reputation: 50
Sorry Sergei- I don't know Perl, so have little idea of what you just said.

Especially this sentence:
Quote:
objects are best represented as scopes into which interrelated datum and functions are encapsulated, with, as necessary, usage of closures.
Thanks for the link though.

TG
 
Old 02-01-2010, 08:16 AM   #13
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by titanium_geek View Post
Sorry Sergei- I don't know Perl, so have little idea of what you just said.

Especially this sentence:


Thanks for the link though.

TG
OK, then think about anonymous classes in Java. They encapsulate. And, IMO, by default scopes/classes should be anonymous - in order to avoid name clashes.
 
Old 02-01-2010, 09:45 AM   #14
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,421

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
Quote:
Originally Posted by titanium_geek View Post
OK: so ignoring objects and CLOS, what is the best mechanism for representing a "thing" in lisp? Should I use a list?
I want a deck of cards, basically. Then I can work out what to do with them later. Is this approach: http://code.tumyr.org/lisp/poker/cards.lisp a decent one?
I would probably use defstruct, but the specific representation doesn't really matter as long as the abstract interface is used (create-card, card-value, card-suit, ...).

Quote:
Originally Posted by Sergei Steshenko
Regarding data representation - look at 'cond' construct too - to me it looks kind of like hash in Perl (in a sense), i.e. if I understand correctly, it is possible to imitate access to hash table using "key" as input and getting its "value" as output. Probably LISP macro mechanism can be used to add "key" "value" pairs.
cond is more like an "if else if ... else" conditional construct. Common Lisp has hashtables as well as the more traditional Lisp Association Lists.
 
  


Reply

Tags
lisp


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advice for a "beginner" using PHP with MySQL custangro Programming 8 08-15-2009 08:58 PM
NISPOM audit requirement "failed access to objects" won't work-RHEL5 update1 p3t0rt Red Hat 1 05-14-2009 11:36 AM
Input without pressing "Enter" in Lisp? andrw123 Programming 2 10-15-2008 12:12 AM
Question of a beginner: "how to install this program" yjunhu Linux - Software 3 10-20-2007 01:45 AM
Does anyone know the origin of using "~" to represent the user's home directory? GonzoJohn General 6 10-14-2003 03:42 PM


All times are GMT -5. The time now is 08:53 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration