«Home

Any Lisp/scheme Programmers In Here?

Anyone here program in Lisp / Scheme?

Any interests in Artificial Intelligence?

Avatar
Newbie
28 answers

Hi,

I know this is a bit late however Scheme(and other LISP implementations) give one very powerful constructs NOT available in more conventional programming languages like;

1. Continuations - try storing an outstanding computation, jumping into and out of computations in other languages this allows one to implement coroutines and multitasking and other complex program flow constructs

2. Use of closures - implement OOP

3. Define your own language constructs...try defining your own "when" key word in non lisp languages or your own "if"

0
Avatar
Newbie

@DonSegmond

Hi.i hope ur still available. I've got this question-in some algorithms, can using a primitive operator that calculates the square of an arguement and calculating the square explicitly by multiplication result in different algorithm growth?

0
Avatar
Newbie

LOL@read economics by mistake. I wish I had studied economics in school! I don't program for a living, I haven't programmed much for fun either, and the hacker culture is dead in my opinion. The only serious project I want to tackle is true AI and that's because no one else is doing, partially motivated by the challenge, the fun and the wealth. Knowing how to write efficient algorithms comes with learning algorithms, if you don't study them, you will never learn some of them or figure them out. Get a book on data structures and algorithms. The cool thing about lisp tho is that it provides alot of those algorithms and data structures to you, so you don't have to reimplement them, you have resizeable arrays, lists, vectores, it's easy to implement queues and a stack, built in hashtables, sort, search. So Common Lisp does a lot for you so you don't have to be a pro.

0
Avatar
Newbie

thats cool.i'm curious, do u program for a living? if you do, do you program full time?if you don't program for a living, do you program for fun or to advance hacker culture i.e improve somethings (maybe go on to be a wealthy software giant kinda thing).

I'm asking cos i'm actually an accountant. i read economics by mistake so now i do programming part time with the intent of going full time hacking especially to take opportunity of the many under-utilised internet opportunities in Nigeria,maybe even africa.

also,does knowing how to write efficient algorithms (instead of brute-force-just-get-the-solution methods that my brain always seems to produce) come with experience or just smartness or both cos 18 lines to do 300 lines job is something that has gotten me very jealous. i've been battling with writing lisp code to do exponentiation and the condition is that it should be a logarithmic iteration.today is my second day

0
Avatar
Newbie

nice.

I'm learning Scheme first while learning how to program. After I finish the SICP book, i'll probably move over to Common Lisp. I have to admit, im enjoying this scheme ride. But i'm still gonna learn python and perl.

Will LISP be very good for building an online payment gateway?I think it should since it sort of falls into AI domain (at least the fraud detection part does)

0
Avatar
Newbie

yeah, MIT Scheme is probably keeping to standards.

Yeah, I have been strictly common lisp, this is the first time I'm installing and playing with scheme. But I really want to read through that book "Structures and Interpreations of Computer Programs" so I will probably learn scheme while reading it, but I probably wouldn't use it.

0
Avatar
Newbie

@DonSegmond

It worked on MIT Scheme like a charm which means i have to research more about this DrScheme. DrScheme is more user friendly, MIT Scheme (Edwin) is very "linuxish" and actually looks like a real hacker's tool (i don't mean cracker o). Thanks for the help.

Are you now strictly into common LISP?

0
Avatar
Newbie

actually in DrScheme (now DrRacket- they have changed the name from Scheme to racket), you can use square brackets for cond expressions (i read that in 'How To Do Programming which is PLT-makers of DrScheme's official book plus i have used it in other codes and it worked.

i made the corrections but it still doesnt work. It seems DrScheme just doesn't allow more than one expression in any procedure definition(that's what the error message seems to be saying). I have downloaded DrRacket and i'm going to download MIT's MITScheme then run both codes like you advised. I'll let you know when i do the comparisons.

meanwhile it seems i really have to understand this LISP and its dialects.

0
Avatar
Newbie

Your problem more than anything else is not that of getting the concepts and idea, but that of making simple mistakes and then not debugging.

For cond you had the [ and ] as tags eg [(< n 3) n], I changed those to ( and )

then you defined calc

as (define (calc counter n1 n2 n3) which means, it takes 4 argument, in the one without lexical scope it took 5 since it had to read n.

however when you called, you kept passing it n as well, 5 arguments.

(calc n (+ counter 1) (step-up n1 n2 n3) n1 n2)))

and

((> n 5) (calc n 5 25 11 4))

so I took out that extra n and it worked.

guile>

(define (func-n n)

(define (step-up n1 n2 n3)

(+ n1 (* 2 n2) (* 3 n3)))

(define (calc counter n1 n2 n3)

(if

(= n (+ counter 1))

(step-up n1 n2 n3)

(calc (+ counter 1) (step-up n1 n2 n3) n1 n2)))

(cond

((< n 3) n)

((= n 3) 4)

((= n 4) 11)

((= n 5) 25)

((> n 5) (calc 5 25 11 4))))

guile> (func-n 6)

59

guile> (func-n 7)

142

guile> (func-n 10)

1892

guile> (func-n 20)

10771211

perhaps the scheme I'm using is giving a much better description of error? In which case, I will suggest you download 2 more different type of scheme interpreters. and run your code on them.

here is an example of the message I got, after fixing the [ and ] in the cond

guile> (func-n 6)

Backtrace:

In standard input:

34: 0* [func-n 6]

In unknown file:

?: 1 (letrec ((step-up #) (calc #)) (cond (# n) (# 4) (# 11) , ))

In standard input:

,

29: 2 [calc 6 5 25 11 4]

standard input:29:14: In procedure calc in expression (calc n 5 , ):

standard input:29:14: Wrong number of arguments to #<procedure calc (counter n1 n2 n3)

It correctly points out that the error is at line 14, then it shows me that it's calling calc with 6 5 25 11 4 (five arguments), then it tells me wrong number of arguments to the calc procedure which is defined with just 4 arguments (counter n1 n2 n3).

So you have the right ideas, it's just silly mistakes and seeing them then debugging em. :-)

0
Avatar
Newbie

oops,

should have been this:

(define (func-n n)

(define (step-up n1 n2 n3)

(+ n1 (* 2 n2) (* 3 n3)))

(define (calc counter n1 n2 n3)

(if

(= n (+ counter 1))

(step-up n1 n2 n3)

(calc (+ counter 1) (step-up n1 n2 n3) n1 n2)))

(cond

[(< n 3) n]

[(= n 3) 4]

[(= n 4) 11]

[(= n 5) 25]

[(> n 5) (calc 5 25 11 4)]))

n in func-n is now a free variable so i didnt include it in the definition of calc.

0
Avatar
Newbie

@DonSegmond:

this is what i think that snippet should look like with lexical scoping:

(define (func-n n)

(define (step-up n1 n2 n3)

(+ n1 (* 2 n2) (* 3 n3)))

(define (calc counter n1 n2 n3)

(if

(= n (+ counter 1))

(step-up n1 n2 n3)

(calc n (+ counter 1) (step-up n1 n2 n3) n1 n2)))

(cond

[(< n 3) n]

[(= n 3) 4]

[(= n 4) 11]

[(= n 5) 25]

[(> n 5) (calc n 5 25 11 4)]))

Like i said earlier,i don't know if i'm wrong (but DrScheme does think i am wrong). It seems DrScheme does not allow more than one expression when creating a procedure. Is it a LISP thing or I should just start reading the book all over again?

0
Avatar
Newbie

hmm for some reason, I'm not seeing this topic in the mainthread, I had to look at your last post to see it. I wonder if it's an issue with nairaland,

0
Avatar
Newbie

@DonSegmond

silly me, you were right. i didnt think towards that angle cos i would have been expecting to see an error like this:

reference to an identifier before its definition: average. Thanks

sorry to bother you again but help me out with this code:

;;A function f is defined by the rule that f(n) = n if n<3 and f(n) = f(n - 1) ;;+ 2f(n - 2) + 3f(n -3) if n> 3. Write a procedure that computes f by means ;;of a recursive process. Write a procedure that computes f by means of an ;;iterative process.

(define (func-n n)

;; f(1),f(2),f(3),f(4),f(5) are already calculated

(cond

[(< n 3) n]

[(= n 3) 4] ;;pre calculated f(3)

[(= n 4) 11] ;;pre calculated f(4)

[(= n 5) 25] ;;pre calculated f(5)

;; calc will do the calculation from f(6) and above

;; calc consumes

;;*a number n(which is user defined as in f(n),

;;*a number counter (a counter to determine where the program should stop and return,

;;*3 starting numbers to calculate the iteration

[(> n 5) (calc n 5 25 11 4)]))

(define (calc n counter n1 n2 n3)

(if

(= n (+ counter 1))

(step-up n1 n2 n3)

(calc n (+ counter 1) (step-up n1 n2 n3) n1 n2)))

(define (step-up n1 n2 n3)

(+ n1 (* 2 n2) (* 3 n3)))

I want it written so that i can make use of lexical scoping. You can write it in common LISP, i should be able to understand. i have my own "solution" (it looks right to me) but it didnt work. It gives me the error i mentioned earlier and in this case all the function

just in case its different in common LISP, ";;" starts a comment

0
Avatar
Newbie

I don't do scheme, but common lisp, so I just intalled guile, but when I run it, I get error on (square)

is (square) defined in your implementation?

also, (average), does your scheme implementation provide those?

(expt) works for me

so to square 3 (expt 3 2)

so i changed square to expt and i implemented my own average and it works.

So you have it right, the code really works without modification if you have average and square.

guile> (define (sqrt x)

(define (good-enough? guess)

(< (abs (- (expt guess 2) x)) 0.001))

(define (average num1 num2)

(/ (+ num1 num2) 2))

(define (improve guess)

(average guess (/ x guess)))

(define (sqrt-iter guess)

(if (good-enough? guess)

guess

(sqrt-iter (improve guess))))

(sqrt-iter 1.0))

guile> (sqrt 81)

9.00001129879022

0
Avatar
Newbie

i understand lexical scoping. what i dont understand is why that code didnt work

0
Avatar
Newbie

please help me with this code.It is supposed to be an implementation of lexical scoping

The initial code is this:

(define (sqrt x)

(sqrt-iter 1.0 x))

(define (sqrt-iter guess x)

(if (good-enough? guess x)

guess

(sqrt-iter (improve guess x) x)))

(define (good-enough? guess x)

(< (abs (- (square guess) x)) 0.001))

(define (improve guess x)

(average guess (/ x guess)))

Taking advantage of lexical scoping it should be like this:

(define (sqrt x)

(define (good-enough? guess)

(< (abs (- (square guess) x)) 0.001))

(define (improve guess)

(average guess (/ x guess)))

(define (sqrt-iter guess)

(if (good-enough? guess)

guess

(sqrt-iter (improve guess))))

(sqrt-iter 1.0))

;;and that is exactly what is in the book i am reading.

However, when i run it on DrScheme i get this error:

define: expected only one expression for the function body, but found at least one extra part (referring to where improve is being defined)

The text book i am using is MIT's 'Structure and Interpretation of Computer Programs' so i'm wondering how can this be wrong. I tried changing the mode of my DrScheme to Advanced mode but still the same error(i'm using beginner mode).

Can anyone help me with the problem?

0
Avatar
Newbie

@Tomx

LISP is still the most suitable language for complex applications and like DonSegmond said earlier, its early implementation was hampered due to its hardware requirements. I am personally attracted to LISP because of its macros which is a program that writes another program which might write another program. Now thats powerful

0
Avatar
Newbie

i love the buccaneer let me be a full member, i love this game

0
Avatar
Newbie

I've have been doing things like that even with rudimentary Javascript and PHP does it elegantly too. Programs like C++ takes it to a whole new level! To say C++ cannot do this simply saying you are not familiar with the platform. What do you think Your Visual Studio Compiler is built with? Visual C++. Most microsoft products are also built with Visual C++ and they all have macro tools and inbuilt programing interfaces. Many code generators are built with C++ and Java. This is no news.

In any programing effort that goes beyond rudimentary level, debuging, portability and continuity are issues of big consideration. If your codes are not readable then you will find that it is of little use even to you the developer when you have to debug and / or update it much latter.

When you use a script generator like your visual compilers, web development softwares etc, what are they doing? they are generationg codes in response to the things you do and the choices you make. These softwares were not built with lisp.

Not realy true! In the early years access to compilers for almost all kinds of program (FORTRAN, FORMIAN, C, BASIC, COBOL, PASCAL, etc) even the ones you have not heard about where "through workstations in the academia environment" to qoute you. The advent of Personal computing changed the trend and as expected most programmers concentrated their efforts on the platforms that where more robust (stable), more powerful, more elegantly deployable etc. This became the age of C++, VB, Java, PHP Pearl, etal.

True Some people still work on lisp but hell even FORTRAN and COBOL and such likes have newer versions too but their age is past.

I trust in the fact that most AI programmers are not silly. If LISP was a better platform then most of these very smart people would 've been using it. It's lack of popularity is because it is not the best tool for the job. It can do the job but it's not the best , not by a mile.

0
Avatar
Newbie

@all

What are the advantages of lisp to other languages like C,python?

What types of programing is lisp mostly used for?

0
Avatar
Newbie

@DonSegmond,

The concept of abstraction is inherent in all OOP languages.The thing is how readable is a language like lisp and how proficient is it when it comes to builsding robust apps. Programes that even use lisp as a scripting language are not even built with lisp. as for readability I wouldn't compare

Lisp:

(- (* (+ x y) (/ a b)) c)

with C/C++:

((x+y)*(a/b)) - c;

0
Avatar
Newbie

@tundebabzy,

the syntax is not funny. don't forget, code is data is code is data.

code is data, data is code.

alot of people love to argue that code can be data, in other languages, but this is not true, once you get the hang of this, you can do amazing things.

for example in C, we might have

int foo (int x, int y) {

return (x + y);

}

which get's called as foo(6, 7);

however note in scheme/lisp we have

(defun foo (x, y) (+ x y))

which get's called as (foo 6 7)

they are both lists, the defun/define also looks like a call to a function

that's where the power of that syntax/parathesis comes into play.

as for which part of AI. lol, no part, but every part.

I'm going after a complete general AI system with common sense reasoning and human level intelligence.

0
Avatar
Newbie

@DonSegmond

already have its ebook and been reading it for a while. I also have How to Do Programming which is also a nice one and similar plus videos of MIT's Stucture and Interpretation of Computer Programs course lectures. The syntax is quite funny but i'm enjoying it.

What part of AI are you into or planning to go into?

0
Avatar
Newbie

tundebabzy.

scheme is a very smaller subset of lisp. It's a good start, if you really want to learn it really good, checkout this book. http://mitpress.mit.edu/sicp/ "Structure and Interpretations of Computer Programs. Argueable the best computer programming book ever written for learning to program if one can make such a bold statement. They use scheme, used for main years to teach at MIT.

0
Avatar
Newbie

I just started learning Scheme.hard to look at syntax but i was made to believe that it is the best programming language (apart from Python) to learn programming cos it has a lot of concepts of abstraction that are not present in a lot of other popular programming languages.

, and i'm interested in AI

0
Avatar
Newbie

What about Clojure? I think it may be the most promising modern Lisp.

0
Avatar
Newbie

Hi @Poster,

More out of sheer curiousity than anything else, I cut my teeth on common lisp over ten years ago.

in all that time, aside from a handfull of guys trying their hands on auto-lisp ( a watered down version

of lisp that runs in autocad) I've not met anyone who mentioned lisp let alone works with it.

So what do you want lisp for bro?

0
Avatar
Newbie

Can you post your version making use of lexical scope?

0
Avatar
Newbie
Your answer
Add image

By posting your answer, you agree to the privacy policy and terms of service.