| |
|
Welcome to AstaHost - Dear Guest | |
Toggle shoutbox
Shoutbox
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Scheme And Lisp
#1
Posted 09 February 2005 - 02:48 AM
#2
Posted 09 February 2005 - 02:53 AM
*/
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
#3
Posted 09 February 2005 - 03:22 AM
#5
Posted 13 February 2005 - 12: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.Hey nice post
Do you have the original Scheme or Lisp code or both ? If so, can you please post them here ??
Thanks
#6
Posted 19 February 2005 - 04:57 PM
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
#7
Posted 19 February 2005 - 05:17 PM
#8
Posted 26 June 2006 - 12:55 PM
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!
#9
Posted 08 August 2006 - 11:10 PM
Reply to this topic
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











