Jump to content
xisto Community
loudthings

Scheme And Lisp dicussion of these two languages

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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;elsereturn func(car(lst), accumulate(func, initial, cdr(lst)));}function position(e, lst) {if (e == car(lst))return 0;elsereturn 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;elsereturn 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Hey nice post :P Do you have the original Scheme or Lisp code or both ? If so, can you please post them here ??

Thanks

<{POST_SNAPBACK}>

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.

Share this post


Link to post
Share on other sites

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.

<{POST_SNAPBACK}>


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 :P Thanks all the same...

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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! :(

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.