Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Scheme And Lisp, dicussion of these two languages
loudthings
post Feb 9 2005, 02:48 AM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 9-February 05
Member No.: 2,569



I would like this topic to be a place where information about these two languages can be shared. LISP is a conceptual beautiful list based language. It is the language used to teach structure and interpretation of computer programs at UC Berkeley and is the language used to write the infamous chess-playing Deep Blue.
Go to the top of the page
 
+Quote Post
loudthings
post Feb 9 2005, 02:53 AM
Post #2


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 9-February 05
Member No.: 2,569



I have implemented the basic Scheme primitive procedures as well as some of the most useful higher-order procedures in JavaScript. They are as follows: /* Scheme implementation in JavaScript
*/

function cons(e1, e2) {
return function(msg) {
if (msg == 0)
return e1;
else
return e2;
}
}

function car(aPair) {
return aPair(0);
}

function cdr(aPair) {
return aPair(1);
}

function list() {
var theList = cons(arguments[arguments.length - 1], null);
var c = 2;
while (c <= arguments.length) {
theList = cons(arguments[arguments.length - c], theList);
++c;
}
return theList;
}

function length(lst) {
var c = 0;
while (lst != null) {
lst = cdr(lst);
++c;
}
return c;
}

function item(pos, lst) {
var c = pos;
while (c != 0) {
lst = cdr(lst);
--c;
}
return car(lst);
}

function append(lst1, lst2) {
var c = length(lst1) - 1;
while (c >= 0) {
lst2 = cons(item(c, lst1), lst2);
--c;
}
return lst2;
}

function map(func, lst) {
var c = length(lst) - 1;
theList = cons(func(item(c, lst)), null);
--c;
while (c >= 0) {
theList = cons(func(item(c, lst)), theList);
--c;
}
return theList;
}

function filter(pred, lst) {
var c = length(lst) - 1;
theList = null;
while (c >= 0) {
if (pred(item(c, lst)) != false)
theList = cons(item(c, lst), theList);
--c;
}
return theList;
}

function accumulate(func, initial, lst) {
if (lst == null)
return initial;
else
return func(car(lst), accumulate(func, initial, cdr(lst)));
}

function position(e, lst) {
if (e == car(lst))
return 0;
else
return 1 + position(e, cdr(lst));
}

function isAtom(x) {
return typeof x == "string" || typeof x == "number" || typeof x == "boolean";
}

function not(x) {
if (x == false)
return true;
else
return false;
}

function isPair(x) {
return not(isAtom(x));
}

function flatten(lst) {
if (lst == null)
return null;
else {
if (isPair(car(lst)))
return append(flatten(car(lst)), flatten(cdr(lst)));
else
return cons(car(lst), flatten(cdr(lst)));
}
}


I have tested all the procedures, though not thoroughly, and they appear to work. This allows Scheme to be easily used for interesting web programs. Please feel free to add to these, report bugs, and post fixes. Contact me at tberg@berkeley.edu
Go to the top of the page
 
+Quote Post
loudthings
post Feb 9 2005, 03:22 AM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 9-February 05
Member No.: 2,569



I am writing, using the scheme implementation in JavaScript that I posted earlier, a program that is a performance artwork. It is based on the digital artwork Galapagoes. Yet instead of evolving images, it evolves poems using user preference as natural selection. And instead of being in a galary somewhere it will be posted on the web so that many users can access it. It works be generating six poems by randomly picking words from a word bank. These initial poems are pretty much incoherent. Then the user picks the two of these poems that he or she likes best (likely the most coherent of these six). then the program takes a sort of numerical dna that encode the positions of the words in the two poems in the word bank. These two dna sequences are combined and slightly mutated, in effect creating an offspring of the two that has traits of each. The reproduction process is sufficiently random and variably that many offspring can be produced that are all different, but all have traits of the parent poems. The two poems are reproduced six times to create six new poems, the next generation. Then the user picks two from this generation, and the process continues. As this goes on, with many different user's input, each picking up with the last generation created by the last user, a sort of evolution occurs in the poems. They get more and more coherent and more and more interesting. User input in preference is the element of natural selection in the evolution. I hope to have the work up on a website soon. Im still working on the php to be able to record the last generation, so a new user can pick up the process where the last left off. I will post the URL of the website as soon as it is running.
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Feb 9 2005, 02:42 PM
Post #4


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



Hey nice post smile.gif Do you have the original Scheme or Lisp code or both ? If so, can you please post them here ??
Thanks
Go to the top of the page
 
+Quote Post
loudthings
post Feb 13 2005, 12:47 AM
Post #5


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 9-February 05
Member No.: 2,569



QUOTE(microscopic^earthling @ Feb 9 2005, 07:42 AM)
Hey nice post smile.gif Do you have the original Scheme or Lisp code or both ? If so, can you please post them here ??
Thanks
*


thanks, man. which original code do you mean? for the implementation of the languages? i have a metalinguistic implementation of a scheme interpretter (i. e. written in scheme). or do you mean for my project? i will post both! let me go get them.
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Feb 19 2005, 04:57 PM
Post #6


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



QUOTE(loudthings @ Feb 13 2005, 07:47 AM)
thanks, man. which original code do you mean? for the implementation of the languages? i have a metalinguistic implementation of a scheme interpretter (i. e. written in scheme). or do you mean for my project? i will post both! let me go get them.
*



Kinda...I meant the scheme/lisp versions of this code... I'm trying to pick up a little of lisp mysqlf - and I know a fair bit of javascript - so if I you could possibly post the lisp code in here - I'll be able to compare the syntax and make life a little easier for myself tongue.gif Thanks all the same...
Go to the top of the page
 
+Quote Post
overture
post Feb 19 2005, 05:17 PM
Post #7


Premium Member
Group Icon

Group: Members
Posts: 208
Joined: 6-September 04
From: England
Member No.: 315



cool Loudthings. I am gonna be learning lisp in the future due to my college work. We have a new unit called Expert Systems (Artificial Intelligence) and were are supposed to be programming our own little AI program when we learn enough. It all seems very interesting to me.
Go to the top of the page
 
+Quote Post
KazDoran
post Jun 26 2006, 12:55 PM
Post #8


Member [ Level 1 ]
Group Icon

Group: Members
Posts: 49
Joined: 7-March 06
Member No.: 11,803



After finishing my AI project, and having used Scheme as the language in another AI-related project, here's my thoughts:

Both Scheme and LISP are very powerful languages, as they allow for simple manipulation of data by hiding most of type verification.

Both languages earn a thumbs-up for allowing easy definition of abstract data-types. LISP has the advantage to allow some degree of OO programming through it's implementation of classes. It also allows to define structures in their own manner, creating the constructor and accessors automatically, which is definitely a plus.

The "everything is a list" point of view of both these languages can be at any time very useful, or very annoying, but it's nothing going against these languages.

Scheme, at a first glance, looks like a simplified version of LISP, by using the "define" form for (nearly) every declaration, as opposed to LISP, which uses a different form for different data types: "defun", "defvar", "defconst", etc...

LISP has the advantage (to some, a disadvantage) of allowing the same name to be used for several data types. You can define a function called "x" and then assign a value to x, and still use the function.

As for debugging, I found Scheme simpler to debug than LISP using the default options (I used Dr. Scheme to code in Scheme and Allegro, connected to Emacs through Slime, to code in LISP). Scheme gives away a very graphical debug info, with arrows pointing to where a function was called, or conflicts between names and/or arguments, as LISP only splattered about the steps in plain text mode, most often showing info about the internal procedures it uses to run our higher level code.

My two cents on this! smile.gif
Go to the top of the page
 
+Quote Post
mitchellmckain
post Aug 8 2006, 11:10 PM
Post #9


Premium Member
Group Icon

Group: [HOSTED]
Posts: 361
Joined: 28-April 05
From: Salt Lake City, Utah
Member No.: 4,500



I recently wrote an introduction to Emacs lisp for the tutorial section. I use emacs lisp all the time for quick calculations and to analyze charts of data which I download from the internet. My relativity and space simulator relspace accepts many data formats but I often found it necessary to calculate estimates for missing data on all kinds astronomical objects so they could be included in my program. Nothing beats emacs for a quick and easy way of accomplishing this if you just have a little knowledge of how to program in lisp.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Languages Worth Learning(21)
  2. Function Programming - About Function Languages(1)
  3. Languages In The Workplace(1)
  4. Emacs Lisp(0)
  5. Names Hacking(1)
  6. Localizing Python(1)
  7. How To Use Arabic Or/and Right To Left Languages In Macromedia Dreamweaver(2)
  8. Unfair Evaluation Scheme(3)
  9. If Programming Languages Were Cars...(4)
  10. What Language Is That?(16)


 



- Lo-Fi Version Time is now: 7th July 2008 - 12:40 AM