PDA

View Full Version : Land of Lisp



danbaron
11-01-2011, 08:54
I just got this e-book. And, I just started it. It looks really good.

http://www.nostarch.com/lisp.htm

The book recommends using CLISP, as you replicate the book's examples. CLISP is easy to install.

http://clisp.sourceforge.net/

And, here is another free version of ANSI Common Lisp (also easy to install), which includes an IDE.

http://www.franz.com/downloads.lhtml

To me, Lisp seems substantially different. At first, the learning curve looks like a sheer wall. But, it seems that the people who understand it well, think it is the greatest thing in recorded history. Here is a quote from the book's introduction: -->

:p

Where Does Lisp Get Its Power?

I’ve said that Lisp is a particularly powerful language. So what were the key insights that John McCarthy (and the
other, later innovators of Lisp) had that made this power possible?

To make a programming language powerful, you need to make it expressive. Having an expressive language means that you
can do a lot of stuff with very little actual code. But what traits does a language need to make this possible? I think
there are two that are most important.

One trait is a lot of features built into the language. That way, for most things you need to get done, someone has
already performed some of the work for you, and you can leverage that work to make your own code look pithy. Many modern
languages have this trait. The Java language, for instance, is renowned for powerful libraries that, for example, let
you acquire data from another PC over a socket with ease.

The second trait that gives a language power is letting you muck around inside it as deeply as possible to make it do
your bidding. That way, even if the designers of the language never conceived of what you’re trying to do, you can make
your own changes to the language until it does exactly what you need to solve your problems elegantly. This trait is
much more difficult to provide in a language. Suppose you wanted to add something like nested function definition
support to Java. If you know Java well, thinking about how to add such support is in the realm of nightmares.

The reason most languages aren’t good at supporting both of these traits simultaneously is that they conflict with each
other. The richer a language is at the start, the more complicated it is. And the more complicated the language, the
more painful it is to muck with that language. That’s why making your own changes to the most mature programming
languages is close to impossible.

Of course, if you try hard enough, you can always make fundamental changes to any language. For instance, when C++ was
developed, it originally took the form of a C preprocessor. A special C program was written that could take code written
in the new C++ dialect and convert it into plain-old C, which you could then just run through a standard C compiler.
This is how Bjarne Stroustrup, the inventor of C++, was able to tweak the C language and add features to turn it into
his own. However, writing a translator such as this is an extremely difficult and tedious process that you would
consider only as a last resort.

In contrast, Lisp languages make it extremely easy for an experienced Lisper to alter the compiler/interpreter that runs
a program, while still supporting rich language features with extensive libraries. In fact, messing around with the
language within Lisp is easier than in any other language ever created!

For example, writing a function in Lisp to calculate the distance between two points would be simple, as in most other
languages. But an experienced Lisper would find it equally easy to invent a new way to nest function definitions or
devise a funky if-then command. Even writing your own object-oriented programming support inside Lisp is not complicated
(and most Lispers have probably done so at some point). In Lisp, everyone gets to be a mini-Stroustrup!

How does Lisp make this neat feat possible? One of Lisp’s core characteristics is that writing a Lisp directly in Lisp
is, itself, unbelievably simple. It turns out that this is the key property that allows Lisp to break the paradox of the
two traits. By starting out as a language that could perform a cool mathematical trick of elegantly writing itself, it
ended up possessing the very property needed to be both feature-rich and tweakable. That, in turn, makes it the perfect
tool for actually writing just about any kind of program at all!

Think of it this way: Give a programmer a fish command in his programming language, and he will eat Chinese takeout and
drink Jolt for a day. Give a programmer a programming language that allows him to write his own fish command, and he’ll
eat Chinese takeout and drink Jolt for a lifetime (which, admittedly, would probably be cut short by nutritional
deficiencies, and let’s not even discuss the probable heart arrhythmias).

So, now you have an idea of why Lisp is a very cool and very unusual programming language. It has a long and atypical
history compared with most programming languages. Most languages came from the world of engineering, whereas Lisp
originated from a more mathematical background. It has a lot to offer to those willing to spend a little time learning
something new.

kryton9
11-01-2011, 19:22
Thanks Dan. LISP has been around a while and it is one of the few major languages that I never really tried out. Have you seen some of the LISP books, they are like NYC phone books :)

LanceGary
12-01-2011, 01:16
I just got this e-book. And, I just started it. It looks really good.

http://www.nostarch.com/lisp.htm

The book recommends using CLISP, as you replicate the book's examples. CLISP is easy to install.

http://clisp.sourceforge.net/

And, here is another free version of ANSI Common Lisp (also easy to install), which includes an IDE.

http://www.franz.com/downloads.lhtml

To me, Lisp seems substantially different. At first, the learning curve looks like a sheer wall. But, it seems that the people who understand it well, think it is the greatest thing in recorded history. Here is a quote from the book's introduction: -->



Perhaps you might be interested in Factor, which has some similarities to Lisp and some to Forth. See

http://factorcode.org/

The Land of Lisp book does seem to be very well written...

Lance

danbaron
12-01-2011, 08:53
I agree. Most Lisp books seem designed to be opaque. I hope this one is different.

I don't know how you found Factor. I looked at it for a minute. I have to admit, it looks good, a compiled stack language. I will look at it some more. (I should be content just investigating Lisp, with the new book. But, I'm not constructed that way. I'm always interested in the next language, whether I want to be or not.)

I think a main thing that determines if a language gains popularity, is its documentation. Conversely, the more popular a language becomes, the more documentation it has. When I examine Factor, that is the first thing I will look at. It's hard to learn a newly existent language, because, initially, its documentation is usually lacking. A language seems to break out of obscurity, when books begin being written about it. A complex language seems to require a lot of books, to explain all of its aspects, its possibilities.

kryton9
12-01-2011, 23:05
I guess this is why I never really tried Lisp and Perl.
http://gnuvince.wordpress.com/2007/09/07/perl-vs-lisp/

They seemed similar, but now in looking at this sample code, I could see that Perl perhaps is not as bad as I thought. But again, I have been looking at lots of c++ code the last year or so and that makes it less off putting looking at Perl now.

jack
13-01-2011, 00:01
I have been interested in Lisp for a long time but my procedural mindset keeps me away, not to mention all those parenthesis.
just now I was looking at factor and example code, wound up at the rosetta site looking at different implementations of 99 bottles of beer, the one example that cought my attention was this kid's language scratch it looks cool.
see it here http://rosettacode.org/wiki/99_Bottles_of_Beer#Scratch

danbaron
13-01-2011, 08:20
I also have a procedural mindset.

With non-procedural languages, the simplest things seem hard - maybe I am just ignorant.

If you want to drive yourself crazy, try to figure out how to do I/O, in Haskell.

Haskell web page:

http://haskell.org/haskellwiki/Haskell

Haskell I/O:

http://www.haskell.org/haskellwiki/IO_inside

More Haskell I/O:

http://www.haskell.org/tutorial/io.html

More Haskell I/O:

http://en.wikibooks.org/wiki/Haskell/YAHT/Io

More Haskell I/O:

http://en.wikibooks.org/wiki/Haskell/Understanding_monads/IO

So far, Haskell is my winner for the language which is closest to being the opposite of Basic.

The "Scratch" version of 99 Bottles, looks good. "When", "set", "repeat", "say", "wait". And, the cat performs. That's the way to get kids interested. Learning that is fun, i.e., painless.

-----------------------------------

In Lisp and Perl (also, I think in Lua, Python, and Ruby), functions are referred to as, "first class objects". I think that means that anything you can do with any other object, you can do with them. For instance, like in your article, a function can build and return another function.

You can download, "Higher Order Perl". I downloaded it a couple of weeks ago. I always get side-tracked. Anyway, if you are just starting with Perl, you probably should study, "lower order" Perl, first.

-----------------------------------

I hardly know anything about it, but, I'm downloading Factor.

Whatever it is, there must be a lot there, because, the download is 29 MB.

Charles Pegge
13-01-2011, 12:41
If you would like to see any Lisp functionality that would be useful in Basic, here is your opportunity :)

Charles

danbaron
14-01-2011, 08:23
Maybe Factor functionality too, Charles.

I downloaded and installed Factor.

So far, all I know is that inside the IDE, at the "Listener" prompt, you can use it like an RPN calculator.

Here is the blog of Slava Pestov, Factor's creator.

http://factor-language.blogspot.com/

Charles Pegge
15-01-2011, 10:19
Maybe a high level PUSH and POP would be useful additions to Basic. I wrote an experimental interpretive language called R$ which used stacks and Reverse Polish Notation - It worked well for simple coding but then gets messy when you want to use mixed data types, structures, and multidimensional arrays. The Basic/C notation we are all familiar with, is highly optimised with over 40 years of evolution behind it.

However Stack based languages are widely used to mediate between high level languages and native code. For instance: PostScript, Java Byte code and .Net's Common Intermediate Language. (You can include Assembly code itself in this category too).

Charles

danbaron
15-01-2011, 22:05
This stuff is new to my experience.

So far, Factor seems like an RPN calculator to me.

According to what I read, you can put any kind of object on the stack. If for instance, you PUSH an array, it only takes one stack position, i.e., an array of 1000 elements would not use 1000 stack places, as I'm sure you know.

I guess, to call a function, you first put its parameters on the stack, and then you enter only the function's name, I think that's why functions are referred to as words.

Just like on an RPN calculator, if I want cos(x), first I put x on the stack, and then I press the cos button.

So far, what is gained by doing things this way, is not clear to me. Hopefully, there are substantial advantages. Otherwise, why change the method of parameter passing, only for the sake of changing it?

Like I said before, for new languages, you have to do a lot of digging to get an idea of their capabilities. Maybe a language escapes from obscurity, when the the first book is written about it.

If I am not mistaken, I also read that Factor can make compiled executables - Factor is not required to be installed on a machine in order to run a Factor executable on it.

Charles Pegge
15-01-2011, 23:08
Forth, one of the notorious predecessors of stack based languages was often described as a "write-only" language because its code was so difficult to understand once written.

I suppose the main advantage is brevity and ease of compiling. There are very few syntax rules and you can generate machine code in a single pass - just about.

These are good characteristics for an intermediate language but needs very good commentary to explain what each procedure is doing if it is to be understood by human programmers.

Charles

danbaron
16-01-2011, 08:19
Slava Pestov writes about how Factor is different from Forth. I don't know what to make of it. The only things I know about Forth, is what you wrote, and what I just read on Wikipedia.

Forth is untyped, not garbage collected, and close to the machine. For flow control, Forth code tends to use immediate words. Variables and arrays tend to be global, and programs aren't usually written in a functional manner. Factor is very different from this. It is dynamically typed, offering a high degree of reflection. Unreferenced objects are garbage collected with a generational garbage collector. Factor code is a little bit more distant from the machine, though the C FFI allows using words like malloc and mmap. For flow control, Factor generally uses quotations, allowing flexible higher order functions; parsing words are used mostly for definitions and data literals. Variables are dynamically or statically scoped (see below), and arrays are just objects which don't need to be treated specially.

kryton9
16-01-2011, 09:04
I felt like watching a programming video tonight and came upon this one of Factor.
I like that he goes into examples instead of detailed language syntax in the video.

http://www.youtube.com/watch?v=f_0QlhYlS8g

danbaron
16-01-2011, 12:53
My connection is too slow to watch it.

I wish I could.

I'm trying to understand the language.

zlatkoAB
16-01-2011, 15:55
I dont know what is so interesing in LISP...
And for what kind of application this language is good?
For me far interesting languages are Clipper(harbour) compiler,
Euphoria,seed7...

Charles Pegge
16-01-2011, 18:27
I remember watching this video some time ago. I like the idea of the stack based language that is so flexible and integrates so many paradigms but I just can't see it being adopted outside academia. It is too far removed from Basic C Java Pascal or even Assembler (which is a very natural and easy to understand stack language :whatever the processor :) )

If a non-programmer is able to read the script and make some sense of it then the programming language has some chance of success.

Charles

kryton9
16-01-2011, 23:37
I would actually recommend this language to someone who has never programmed before. If you come in with a clear mind and void of any programming concepts and had to learn everything from scratch, then I think learning it would be much easier.

I love how concise and well thought out the language is. The interactivity, support for various programming styles and the optimized compilation.

Also it seems like it would be great for creating your own language and have it be cross platform. If you see the part where he shows the javascript interpreter it is just a couple of pages of code, if that even.

I am glad he showed also how much documentation there is for the language and the wonderful tracing system called the walker.

danbaron
17-01-2011, 03:28
I am trying to determine why some people say Lisp is so great. I haven't yet.

-----------------------------

Since I am finding it difficult to begin in Factor, I looked for a book about Forth.

There is a free one online.

http://www.forth.com/starting-forth/

Also there, but for sale, is SwiftForth. It is $395. That is too much for me, but, maybe you feel you just must have a Forth system!

:p

Charles Pegge
17-01-2011, 11:58
Singing the praises of LISP...

If Lisp is so great
2003
short article
http://www.paulgraham.com/iflisp.html

Beating the Averages
2003
long article
http://www.paulgraham.com/avg.html

danbaron
18-01-2011, 07:48
OK, I read both articles.

They are good.

Therefore, I guess it is obvious that the sensible thing to do is to rewrite thinBasic in Lisp, and release it as version 2.0.

According to the second article, we should not expect Eros to see the great advantages of doing this. So, we (being more enlightened), must gradually make him aware of the fantastic new possibilities, and the huge increase in potential, that this change will permit.

;)


P.S.
Maybe I posted this before, I don't remember.
But, here is the free online version of, "Practical Common Lisp", by Peter Seibel.

http://www.gigamonkeys.com/book/

Charles Pegge
19-01-2011, 00:53
This article reminds me of:

"Those who know do not speak and those who speak do not know"

The Truth About Lisp
2006
http://secretgeek.net/lisp_truth.asp

kryton9
19-01-2011, 06:27
It is a very elegant way to go. It is just so foreign, if you come from any other language. That is why perhaps it should be the first language for anyone coming in with a clear mind.

Charles Pegge
19-01-2011, 07:22
One of the links at the end of this article was for NewLisp. What immediately impressed me about the NewLisp web site was the well presented web pages and the 2011 date!

http://www.newlisp.org/index.cgi?page=Home

Slide Show (overview of the language)

http://www.nuevatec.com/manual-intro.html

I am sure we can learn something here for Basic.

Charles

danbaron
19-01-2011, 07:23
That's really a good article - this one.

http://secretgeek.net/lisp_truth.asp

After it, it seems there's not much left to say.

It does make the point, that for some, maybe Lisp is a religion - a cult?

I can't argue with the notion that Paul Graham was written in Lisp.

And, of course, what language could be written in itself, except for Lisp?! It's a mystery that reminds me of the Christian concept of the Trinity - three individual persons of one substance, who together, comprise, God.

I find a similar analogy with the fundamental particles of physics. Atoms are made of electrons, protons, and neutrons. Electrons, protons, and neutrons, are made of quarks. Either the chain continues forever, or, there is some fundamental and indivisible particle. In that case, my first question would be, "What is it made of?". And, I guess the only answer could be, "It is made of itself.". A person might then ask, "How can something be made of itself?". Likewise, a non-member of the Lisp Illuminati might ask, "How can Lisp be written in Lisp?".

Or, a person might wonder, "How can someone lift himself into the air, by pulling on his own boot straps?". It seems impossible, but we know it can be done. Likewise, 33rd degree Lispers, know how Lisp was first written in Lisp!

Maybe, Eros should start again from the beginning, and this time, write thinBasic, in thinBasic!

Ooga booga!
Ooga booga!
Shazzamm!!
:mad:

(I forgot. Charles' quote (above) reminds me of two quotes I sort of remember, and maybe can paraphrase -

"If you think you understand quantum mechanics, then you don't understand it." - Neils Bohr

"I would never belong to any club that would have me as a member." - Groucho Marx)

danbaron
19-01-2011, 08:39
I've had NewLisp installed on my computer for a while.

I haven't used it.

The problem I have with it is, I can find no documentation about how to start the IDE, and I have been unable to figure out how to do it by myself.

Charles Pegge
19-01-2011, 13:19
If installation was okay it puts an icon on your desktop. It needs Java though - for the IDE I presume. Do you have Java installed Dan?

If not then it should be possible to create our own Lisp with a few lines of thinBasic :)

Charles

Petr Schreiber
19-01-2011, 13:45
If not then it should be possible to create our own Lisp with a few lines of thinBasic :)

These were my thoughts when I attended to LISP classes at school. The language seems designed to be easily implementable (still not sure if as easily usable for the coder as well :))

I liked some stunts in LISP, but I must admit I would not like to use it for bigger project. On the other side, I have seen LISP used as scripting tool in some game engines.


Petr

Charles Pegge
20-01-2011, 00:04
Easy to implement as an interpreter Petr but considerably harder to compile. Dynamic scoping necessarily requires a utility to resolve which variables are available to a function at any time.

I think Basic could well benefit from some kind of Lispish paradigm for handling high level data.

Is Lisp safe to use I wonder? Did your LISP instructors show any signs of brain damage :)

Charles

danbaron
20-01-2011, 09:18
I have the Java 1.6 SDK, Charles.

I have the dragonfly icon on my desktop, but it doesn't work properly. Double clicking on it opens the jar file in PowerArchiver 2001.

And, when I open a command window inside the NewLisp folder, and issue the command,

java -jar guiserver.jar

a console window opens which says,

newLISP-GS v.1.36 on Windows Vista
double buffering supported.
listening on 64001

And, underneath is a blinking cursor.

Nothing more.

I don't know.

I have a commercial editor, "EditRocket", which is written in Java.

I just tried it, and it works fine.

I don't know what is wrong.

:mad:

zak
20-01-2011, 10:08
this is why i have retrogrades from newLisp , even it works on my pc, but in principle they must not used java as a cross platform tool for this language for the ide , i have faced the same dan situation before several years with the same newLisp, so it is not suitable for cross platforming at all. the developers can use QT ,..., but he chooses java.
i can't remeber what i have done but i guess i have reinstalled the windows.

Petr Schreiber
20-01-2011, 10:41
Easy to implement as an interpreter Petr but considerably harder to compile. Dynamic scoping necessarily requires a utility to resolve which variables are available to a function at any time.

I think Basic could well benefit from some kind of Lispish paradigm for handling high level data.

Is Lisp safe to use I wonder? Did your LISP instructors show any signs of brain damage :)

Charles

Yes, I was thinking of interpreter. I never even attempted to write compiler, so cannot judge this.

I don't think the instructor was damaged :p, but what was evident he really likes LISP. I guess it is because his diploma thesis was writing LISP interpreter back in the 60's.


Petr

John Spikowski
20-01-2011, 10:55
The following is a Gtk example in newlisp, ScriptBasic and PowerBASIC using a shared object interface (DLL) version of GTK-Server.

newlisp


#!/usr/bin/newlisp
#
# Demonstration on how to use the GTK-server as Shared Object with NEWLISP.
# Tested with newLISP 8.7.1 on Slackware Linux 10 and Windows2000
#
# December 17, 2005, PvE.
#------------------------------------------------------------------

# Setup gtk-server
(import "libgtk-server.so" "gtk")

# Optionally enable GTK logging
(gtk "gtk_server_cfg -log=/tmp/demo.log")

# Connect to the GTK-server
(gtk "gtk_init NULL NULL")
(set 'win (get-string (gtk "gtk_window_new 0")))
(gtk (append "gtk_window_set_title " win " \"This is a title\""))
(gtk (append "gtk_window_set_default_size " win " 100 100"))
(gtk (append "gtk_window_set_position " win " 1"))
(set 'table (get-string (gtk "gtk_table_new 30 30 1")))
(gtk (append "gtk_container_add " win " " table))
(set 'button1 (get-string (gtk "gtk_button_new_with_label Exit")))
(gtk (append "gtk_table_attach_defaults " table " " button1 " 17 28 20 25"))
(set 'button2 (get-string (gtk "gtk_button_new_with_label \"Print text\"")))
(gtk (append "gtk_table_attach_defaults " table " " button2 " 2 13 20 25"))
(set 'entry (get-string (gtk "gtk_entry_new")))
(gtk (append "gtk_table_attach_defaults " table " " entry " 2 28 5 15"))
(gtk (append "gtk_widget_show_all " win))

# Mainloop starts here
(set 'event 0)
(while (and (!= event button1) (!= event win))
(set 'event (get-string (gtk (append "gtk_server_callback wait"))))
(when (= event button2)
(set 'tmp (get-string (gtk (append "gtk_entry_get_text " entry))))
(println (append "This is the contents: " tmp))
)
)

# Exit GTK
(exit)
ScriptBasic


#!/usr/bin/scriba
REM
REM Demoprogram for Scriptbasic with the GTK-server as a module
REM Tested with Scriptbasic 2.0 Slackware Linux 10.2
REM
REM December 24, 2005 - PvE.
REM --------------------------------------------------------------------------

IMPORT gtk.bas

GLOBAL CONST NL = "\n"

REM Enable logging (optional)
GTK::gtk("gtk_server_cfg log")
GTK::gtk("gtk_init NULL NULL")
win = GTK::gtk("gtk_window_new 0")
GTK::gtk("gtk_window_set_title " & win & " \"Scriptbasic Demo program\"")
GTK::gtk("gtk_widget_set_usize " & win & " 450 400")
table = GTK::gtk("gtk_table_new 50 50 1")
GTK::gtk("gtk_container_add " & win & " " & table)
button = GTK::gtk("gtk_button_new_with_label Exit")
GTK::gtk("gtk_table_attach_defaults " & table & " " & button & " 41 49 45 49")
entry = GTK::gtk("gtk_entry_new")
GTK::gtk("gtk_table_attach_defaults " & table & " " & entry & " 1 40 45 49")
text = GTK::gtk("gtk_text_new NULL NULL")
GTK::gtk("gtk_table_attach_defaults " & table & " " & text & " 1 49 8 44")

radio1 = GTK::gtk("gtk_radio_button_new_with_label_from_widget NULL Yes")
GTK::gtk("gtk_table_attach_defaults " & table & " " & radio1 & " 1 10 1 4")
radio2 = GTK::gtk("gtk_radio_button_new_with_label_from_widget " & radio1 & " No")
GTK::gtk("gtk_table_attach_defaults " & table & " " & radio2 & " 1 10 4 7")

GTK::gtk("gtk_widget_show_all " & win)
GTK::gtk("gtk_widget_grab_focus " & entry)

REPEAT
event = GTK::gtk("gtk_server_callback WAIT")
IF event = entry THEN
tmp = GTK::gtk("gtk_entry_get_text " & entry)
GTK::gtk("gtk_text_insert " & text & " NULL NULL NULL \"" & tmp & "\n\" -1")
REM Empty entry field
GTK::gtk("gtk_editable_delete_text " & entry & " 0 -1")
ENDIF
UNTIL event = button OR event = win
PowerBASIC


' GTK+ Demo Program
'
' Demo created by John Spikowski - Jan 4, 2006.
'

DECLARE FUNCTION gtk LIB "gtk-server.dll" ALIAS "gtk" (cmd AS ASCIIZ) AS DWORD

FUNCTION PBMAIN()

DIM win AS STRING
DIM table AS STRING
DIM exitbutton AS STRING
DIM entry AS STRING
DIM txtbox AS STRING
DIM radio1 AS STRING
DIM radio2 AS STRING
DIM event AS STRING
DIM tmp AS STRING
DIM response AS ASCIIZ PTR

gtk("gtk_server_cfg log") ' Logging Enabled - set log file path in gtk-server.cfg
gtk("gtk_init NULL NULL")
response = gtk("gtk_window_new 0")
win = @response
gtk("gtk_window_set_title " & win & " " & CHR$(34) & "GTK+ Demo program" & CHR$(34))
gtk("gtk_widget_set_usize " & win & " 450 400")
response = gtk("gtk_table_new 50 50 1")
table = @response
gtk("gtk_container_add " & win & " " & table)
response = gtk("gtk_button_new_with_label Exit")
exitbutton = @response
gtk("gtk_table_attach_defaults " & table & " " & exitbutton & " 41 49 45 49")
response = gtk("gtk_entry_new")
entry = @response
gtk("gtk_table_attach_defaults " & table & " " & entry & " 1 40 45 49")
response = gtk("gtk_text_new NULL NULL")
txtbox = @response
gtk("gtk_table_attach_defaults " & table & " " & txtbox & " 1 49 8 44")
response = gtk("gtk_radio_button_new_with_label_from_widget NULL Yes")
radio1 = @response
gtk("gtk_table_attach_defaults " & table & " " & radio1 & " 1 10 1 4")
response = gtk("gtk_radio_button_new_with_label_from_widget " & radio1 & " No")
radio2 = @response
gtk("gtk_table_attach_defaults " & table & " " & radio2 & " 1 10 4 7")
gtk("gtk_widget_show_all " & win)
gtk("gtk_widget_grab_focus " & entry)

DO
response = gtk("gtk_server_callback WAIT")
event = @response
IF event = entry THEN
response = gtk("gtk_entry_get_text " & entry)
tmp = @response
gtk("gtk_text_insert " & txtbox & " NULL NULL NULL " & CHR$(34) & tmp & CHR$(10) & CHR$(34) & " -1")
gtk("gtk_editable_delete_text " & entry & " 0 -1") ' Empty entry field
END IF
LOOP UNTIL event = exitbutton OR event = win

gtk("gtk_server_exit")

END FUNCTION

END

peter
20-01-2011, 11:07
Hi,


have a nice day!

Charles Pegge
20-01-2011, 13:06
Dan,

If you don't get automatic updates (thinking of your internet service) I would download the latest java from java.com and try reinstalling NewLisp after.

Charles

danbaron
21-01-2011, 00:43
OK, I am downloading jdk-6u23, from Oracle.

It is 76.321 MB.

With my dial-up connection, the download will take approximately forever.

The only good thing is that I use Internet Download Manager. It seems to divide the file into 8 parts, and to download each part simultaneously. Also, if my connection fails, or if I turn off the computer, it can resume the download from where it stopped. If I instead always had to get an entire file in one try, I would be finished, except for the case of small files.

I just had a similar problem with anti-virus software. Probably as you know, each year you have to pay again. And then you have to download the program for that year. I tried different brands. In each, I was able to download the program itself, OK. The problem was downloading the updates to the virus database. The downloads for the virus definitions are done by the anti-virus program, i.e., I cannot use Internet Download Manager. And, my experience is that most of the companies do the updates in an absolutely stupid way - you either get the entire update in one try, or, you have to start the update over again from the beginning. It turns out that the initial updates are so big, that, for me it is impossible to ever succeed - my connection always terminates prematurely.

So, I went to the computer store, and bought Kaspersky Internet Security 2011 (yesterday). It has a CD, so, I thought that most of the virus definitions would be on it. I installed it OK. Then, I pressed the button to do an update. It allowed me to view the update in detail. Joyfully, I watched as many individual files were downloaded - the update was not one giant file. It turns out, that it downloads as many of the little files as it can at one time. If there is a disconnection, it does not start over from the beginning. Today, it is completely updated. You can initiate an update anytime you want, and it also automatically updates itself every two hours. Since it has been installed, it hasn't intruded on my activities in any way. I haven't had to attempt to adjust anything at all. So far, it is "invisible", which, of course, is the way we want anti-virus software to be.

I can see that the days of dial-up connections are winding down (most likely you would say, that they ended a long time ago).

:mad:

Charles Pegge
21-01-2011, 01:11
76 Megs! Java has taken on .NET proportions.

I had a crack at coding LISP on thinBasic. This code is less than 2k making download times tolerable even on a 300 baud acoustic coupler. Remember them?

This is limited to simple arithmetic with literal numbers (double floats)

LeanLisp


'LeanLisp 1

dim as long i,j,k,asci,op,opf,nest,nestop(64),nestopf(64)
dim as string s,t,u,w
dim as double v,accum,nestacc(64)

'-------------------------------------------------------
function getword(s as string, byref i as long) as string
'=======================================================
dim as long a,b
'

while 1
asci=asc(s,i)
if asci<9 then exit while
if asci>32 then exit while
i+=1
wend
'
b=i
'
'CHECK FOR '(' OR ')'
'
if (asci=40)or(asci=41) then
i+=1
else
'
while 1
a=asc(s,i)
if a<9 then exit while
if a<=32 then exit while
i+=1
wend
'
end if
'
function=mid$(s,b,i-b)
'
end function

'-----------
sub opeval()
'===========
if opf then
accum=v
opf=0
else
select case op
case 43 : accum+=v
case 45 : accum-=v
case 42 : accum*=v
case 47 : accum/=v
end select
end if
end sub


'------------------------
sub evaluate(s as string)
'========================
i=1
w=""
v=0
accum=0
nest=0
op=0
opf=0
while 1
w=getword(s,i)
if w="" then exit while
select case asci
case 0 : exit while
case 40
nest+=1
nestacc(nest)=accum : nestop(nest)=op : nestopf(nest)=opf
accum=0 : op=0 : opf=0
case 41
v=accum : accum=nestacc(nest) : op=nestop(nest) : opf=nestopf(nest)
nest-=1
opeval()
case 43 : op=43 : opf=1 '+
case 45 : op=45 : opf=1 '-
case 42 : op=42 : opf=1 '*
case 47 : op=47 : opf=1 '/
end select
'
'check for literal number
'
if (asci>=48)and(asci<=57) then
v=val(w)
opeval()
else 'not a literal number
'
end if
'
wend
end sub

'
'-------
'TESTING
'=======
'
s="
( / ( * ( + 1 2 3 4 ) 3 ) 3 2 )
"
'
evaluate(s)

msgbox 0,v



Charles

danbaron
21-01-2011, 01:29
I absolutely remember 300 baud (that was 300 bits per second, right?).

I remember how happy I was the first time I successfully connected to the university's mainframe, using my Apple IIc.

I tried it, your Lisp works perfectly.

:p

Charles Pegge
21-01-2011, 01:39
Yes that's about 30 bytes per second - allowing for 8 bits + framing bits.

I'll add some more Lisp features later - it's the only way I know how to understand this language :)

Charles

kryton9
21-01-2011, 03:03
Ahhh, the first time I heard those strange sweet modem sounds I was in heaven and making the connection was incredible. My friends and I would spend hours and hours sending each other picture files. Then we ventured online to Genie (http://en.wikipedia.org/wiki/GEnie) and then compuserve.

I don't know if you guys ever saw this, but it is used in Universities I guess to teach language development. I haven't tinkered with it, but it is praised pretty highly.
http://www.antlr.org/

danbaron
21-01-2011, 07:44
(I agree, 30 bytes per second. But, 30 bytes per second was infinitely faster than 0 bytes per second, am I right? :p No future increase in transmission speed can match that first increase (I think).)

I saw it before. I guess it is a tool to, for instance, make writing parsers easier and more systematic. If I was going to try to make a parser, I think I would want to do it by myself, at least at first. That way, if and when I finished, it seems to me I would know how to make a parser, instead of knowing how to use Antlr to make a parser for me.

I guess Antlr could be viewed as a higher level of abstraction. It seems there is no limit to the number of abstraction levels. For instance, I guess someone could develop a tool, say, "Deer", to simplify the use of Antlr. And then, someone could develop a tool, say, "Buck", to simplify the use of "Deer".

Or, say there was a compiled language called, E. Someone could write another language called F, using E. Then, someone could write another language called G, using F. Then, I guess, someone could use G, to write an E compiler??

Mathematica, seems to me to be a tool similar to Antlr. The potential pitfall I see with tools like this, is that a person learns how to use the software, and not, the underlying theory. Imagine, sometime in the future, a commercial software is developed, called, "Super-Worm-Hole-Dark-Energy", which, is used to do research in theoretical physics. Then, maybe people will get PhDs in using it. So, those people will have PhDs in the use of a particular commercial software. Understanding the use of software itself, would have become the ultimate goal. And, of course, the ultimate goal of its developers, would be to sell it for as much as they could, for as far into the future as they could.

But, I am totally ignorant in this area. I think that today, unless you are totally immersed in this stuff daily, like you would be at a university studying computer science, then, before long, the "train" will have left the station, and, you will be standing on the platform, wondering what happened.

(I just thought of something else, maybe not directly related. Who is most likely to know how to write the best computer viruses? Wouldn't it be the developers of anti-virus software? This type of commercial software sells, because, people feel they need to buy it, right? The stronger the need, the more people will be willing to pay. Sometimes, it makes me wonder. At some point, would the anti-virus software CEO realize that he will maximize profit, if half of his employees develop anti-virus software, and the other half develop the viruses which the anti-virus software provides protection from? (Historically, the mafia has done the same thing. It sells, "protection", to local businesses. Implicit in the transaction, is the knowledge by both parties, that the protection is from, the mafia, itself.) In other words, when it comes to politicians, governments, corporations, bankers, the military, spy agencies, the police, the mafia, software developers, etc., who, if anyone, can you trust?)

:eek:

Petr Schreiber
21-01-2011, 10:36
Cool code Charles :)

Maybe to do some microoptimization, instead of using ASC(stringVar, index) you can do something like:


DIM Ascii( len(stringVar) ) AS BYTE AT STRPTR(stringVar)


and then receive the ASCII like:


asciiValue = Ascii(i)



Thanks a lot,
Petr

Mark0
21-01-2011, 11:21
300 bauds... I remember doing remote work with PCAnywhere for DOS at that speed!
It wasn't pretty, but it was surely better than going to the clients' offices! :)

About Lisp, a quote from Eric Raymond:

Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.

ErosOlmi
21-01-2011, 11:34
Huuuuuu ...

thinking at that modem sounds recalled to my mind a lot of full night passed to understand a parallel world (BBS) I didn't understand at that time but fascinated me so much ...

What a flashback !
:D

danbaron
21-01-2011, 20:27
For me, 300 bits per second, or, say, 30 bytes per second, was not that bad. All that was being transmitted, was text. I looked up the average word length for the English language, just now. It said, 6 (5 characters plus 1 space). So, 30 bytes per second, was approximately 5 words per second. That was not terrible.

The next improvement was to 1200 bits per second. That was approximately 20 words per second, which was 4 times better; for just text, not too bad at all.

Of course, if you were transmitting a big file, then you would need patience - but, eventually, the file was transmitted. Big files back then, were nothing like big files, now, right?

Absolutely 300 bits per second, was better than telegraph (Morse Code).

-----------------------------------------

I downloaded and installed the latest Java, jdk-6u23.

I re-installed NewLisp. It still doesn't work.

And now, when I open a console window from the NewLisp folder, and execute the command, "java -jar guiserver.jar", the console output is exactly the same as previously, except that it now says my operating system is Windows 7, instead of Windows Vista.

I then tried downloading and installing the development version of NewLisp, which was just released this month. And, the results were exactly the same.

I think that, at least for now, I am finished with NewLisp.

Charles Pegge
21-01-2011, 22:44
Hard luck Dan! Actually I think the documentation - particularly the concepts are more interesting.

Lisp manages to combine things we treat as distinct in Basic.

There is no difference between expressions and statements.
There is no difference between operators, procedures and functions.
There is no difference between code and data.

@Petr Far worse sins of inefficiency and code crimes to follow :) but to quote D Knuth:



Premature optimization is the root of all evil (or at least most of it) in programming.


Charles

jack
22-01-2011, 02:06
one thing that I found interesting is the use of Lisp in Computer Algebra Systems (CAS), three come to mind, muSimp, Reduce and Maxima.
they all have a user language that the system translates to lisp (as I understand).

here's example code in Reduce to compute legendre polynomials (code snippet is from the Reduce user manual)


procedure p(n,x);
begin scalar seed,deriv,top,fact;
seed:=1/(y^2 - 2*x*y +1)^(1/2);
deriv:=df(seed,y,n);
top:=sub(y=0,deriv);
fact:=for i:=1:n product i;
return top/fact
end;

the code looks a lot easier than Lisp

Richard J. Fateman wrote a package in lisp to simulate the CAS Mathematica called mockmma, you can find it on his website http://www.cs.berkeley.edu/~fateman/ mind you the simulation is very limited but it shows the type of thing that you can do in Lisp

danbaron
22-01-2011, 09:06
I tried some more with NewLisp. No luck. I looked in the forum and found some similar problems. But, I didn't find a solution.

When I double click on the NewLisp desktop dragonfly icon, Windows asks me what application I want to open it with. Whatever I answer, doesn't help. It seems that if I am having this problem, then others must be too. I have difficulty understanding why I can't find anything about it on the website. It seems there is trouble combining "NewLisp-edit.lsp" (Lisp) with "guiserver.jar" (Java). I wonder whose idea that was?



One of the links at the end of this article was for NewLisp. What immediately impressed me about the NewLisp web site was the well presented web pages and the 2011 date!

Maybe it is, "sour grapes", but I still say if you want to see a language, website, IDE, and documentation, that is really well done, then, look at Racket.

http://racket-lang.org/

jack
22-01-2011, 10:25
Dan, I just installed newlisp to see if I would have the same problem as you have,
at first, after installing newlisp, had the same problem, but I din't have Java installed,
installing The Java runtime environment fixed the problem of launching the IDE, but entering a simple expression in the top portion of the IDE gives a black window as soon I enter the closing parenthesis.

Charles Pegge
23-01-2011, 08:56
Lisp and flow



3Psychologists have identified a state of mind called flow in which we're capable of incredible concentration and productivity. The importance of flow to programming has been recognized for nearly two decades since it was discussed in the classic book about human factors in programming Peopleware: Productive Projects and Teams by Tom DeMarco and Timothy Lister (Dorset House, 1987). The two key facts about flow are that it takes around 15 minutes to get into a state of flow and that even brief interruptions can break you right out of it, requiring another 15-minute immersion to reenter. DeMarco and Lister, like most subsequent authors, concerned themselves mostly with flow-destroying interruptions such as ringing telephones and inopportune visits from the boss. Less frequently considered but probably just as important to programmers are the interruptions caused by our tools. Languages that require, for instance, a lengthy compilation before you can try your latest code can be just as inimical to flow as a noisy phone or a nosy boss. So, one way to look at Lisp is as a language designed to keep you in a state of flow.



Practical Common Lisp
http://www.gigamonkeys.com

danbaron
23-01-2011, 09:56
Peter Seibel is good.

--------------------------------

You can download, "Introduction to NewLisp", here - almost 200 pages.

http://www.newlisp.org/index.cgi?Documentation

--------------------------------

And, of course, Jack, we don't have to use the IDE in order to use NewLisp.

I made a file called, "print.lsp".

Its contents is (copied from the book above),


(println)
(dotimes (c 10)
(println c " times 3 is " (* c 3)))
(println)
I opened a console window in the file's directory, and I executed the command,

"newlisp print.lsp" .

The code executes in the console window.

However, after it finishes, you will find yourself at the NewLisp REPL prompt. There is no way to quit the REPL, that I can find, except by closing the console window.

:rolleyes:

danbaron
23-01-2011, 10:33
Here is the first program (word definition) from the Factor help.


! Copyright (C) 2009 <your name here>
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences ;
IN: palindrome

: palindrome? ( str -- ? ) dup reverse = ;So, apparently, "!", means a comment.
You need, "kernel", for the "word", "dup".
You need, "sequences", for the word, "reverse".

"IN: palindrome", means any word definitions will be in the user-defined, "vocabulary", "palindrome". "kernel", and, "sequences", are pre-defined vocabularies.

All word definitions begin with a colon (and I think, a space), followed by the word's name (here, "palindrome?"). (Apparently, in Factor, spaces are important.)

I guess, by convention, predicate words, end with a question mark.

"( str -- ? )", is a , "stack effect declaration". It must follow the word's name. In this case, it means that a string is pushed onto the stack, and then, either true or false is popped off.

"dup", means the string on level 1 of the stack is copied to level 2.

"reverse", means the string on level 1 is reversed.

"=", returns, "t", if the contents of level 1 equals the contents of level 2, else, it returns, "f".

From within the IDE, you can enter,

"USE: palindrome".

Then, you can enter a string, with the quotes.
If, for instance, you enter,

""1234567890poiuytrewqqwertyuiop0987654321"".

And then you enter,

"palindrome?".

The output will be,

"t".

You can see that each of the sub-words in a word definition, is pushed onto the stack and executed, just like on an RPN calculator.

:eek:

kryton9
24-01-2011, 00:36
Thanks Dan for the explanation and example.

Charles Pegge
28-01-2011, 00:24
Here is a more developed LeanLisp to experiment with. It is easy to add new core functions. The test code is at the end of the script and contained within a multiline string. (Speed? Snails will appreciate it. )

LeanLisp Test Piece:


'===============================

(
do

'
'---------------
'LIST PROCESSING
'---------------
'
(set cc (inner (combine (a b c) (d e f) ) ) )
(print cc)
'exit
'
'------------
'CONDITIONALS
'------------
'
'( cond (1) (print "ok") )
( if (= 1 2 ) (print "1 = 2") (print "1<>2") )
'
'-------
'LOOPING
'-------
'
(let counter 2)
(
do
(cond (> counter 4) exit )
(inc counter )
(print "count " counter )
repeat
)
'
'----------------------------------
'CREATING AND INITIALISING VARIABLE
'----------------------------------
'
(let c (+ 12 -3 ) )
(print c )
'
'
'----------------------
'CREATING SIMPLE MACROS
'----------------------
'
(def a (+ 1 2 3 4) )
(def b 3 )
'
'--------------------
'MACRO WITH PARAMETER
'--------------------
'
(def demo-macro (print %1 " " 42 ) )
(demo-macro "ok" )
'
'exit 'leave 'do' block
'
'--------
'FUNCTION
'--------
'
(fun (hypot x y) (sqrt (+(* x x)(* y y))) )
'
(print "Hyponeneuse of 3 and 4 is: " (hypot 3 4) )
'
'-------------------------
'COMPOUND PRINT STATEMENTS
'-------------------------
'
(print "Arithmetic: " / ( * a 3 ) b .5 )
(
print "Hello" " " "World! " 1 2 3 " : " .333
)
'
'-----------------------------
'FUNCTION WITH MANY PARAMETERS
'-----------------------------
'
(fun (many v rest)
(
(print v)
(
do
(if (next x) (print "next param: " x) (exit) )
repeat
)
)
)
(many "many:" 1 2 3)
'
)
'===============================
'END OF LEANLISP PROGGRAM


Charles

danbaron
28-01-2011, 01:37
Wow, I don't know how you did that, Charles!

It absolutely is Lisp, as far as I know.

You implemented Lisp, in thinBasic!

You deserve a programming award, in my view.

Wouldn't it be a great example, to show what thinBasic can do?

Of course, in the interest of promoting thinBasic, Eros could neglect mentioning the fact, that, it requires a great programmer to do it!

I wonder how much aspiring programmers could learn, just by dissecting that code?!

Wow, to me, there's a thousand lines, of real code.

At first I didn't understand why the program execution is written as one long string - Oxygen came into my mind. Then, if I am correct, I realized that you parsed the Lisp, and translated it into thinBasic.

To me, it's an amazing demonstration of how a language, "B", can be implemented in another language, "A".

I swear, this is more advanced than at least 99% of programmers ever do (or even see).

I remember that C++ was originally implemented by translating it into C, as the first step in the compilation. Then, it was compiled with a C compiler - this was before there were any C++ compilers. I read, multiple times, how difficult that was to do. It seems to me, you are doing an analogous thing, translating Lisp into thinBasic, before executing the resulting thinBasic code.

I wonder what would happen, if you, Eros, and Petr, collaborated on a language? Maybe, the shock wave would destroy the planet! Or the solar system!! Or the galaxy!!! Or, maybe the ripple would propagate across the entire multi-verse!!!! And, even beyond!!!!!

Humbly,
Dan
;):p

Petr Schreiber
28-01-2011, 07:45
Charles,

thanks a lot for your sample, definitely very interesting manual for study. I see you even implemented the rest... perfect!


Petr

zak
28-01-2011, 09:47
thanks Charles this is realy a marvelous feat, i suggest to change the LeanLisp to a small module so we can use it like this: uses "LeanBasic".
even in its current state is of a great educational value, thank you

Charles Pegge
28-01-2011, 10:07
Dan,

I've been playing with languages for a very long time (since around 1984). Putting together a Lispish interpreter was refreshingly simple when compared to building a Basic compiler. I wanted to understand how Lisp worked logically, so writing an interpreter was for me the easiest way to focus on this task.

Due to its extremely simple syntax I reckon it only requires about 1/5th of the code size needed for a Basic Interpreter.

Petr,
I am sure This Lisp deviates from the standard in many ways but I could see immediately the indispensibility of "rest" for passing multiple parameters.

Instead of quoting with the single quote mark I introduced the word "quote"

I find that to code in Lisp instead of Basic a different set of brain cells have to be activated :)

Charles

Charles Pegge
28-01-2011, 10:17
Zak,

We could drop this into a module very easily. The virtue of starting out with thinBasic is making the source easily accessible to all interested users here.

Charles

kryton9
29-01-2011, 00:46
Amazing stuff Charles as always!!

zlatkoAB
15-04-2011, 13:50
The name LISP derives from "LISt Processing language". Linked lists (http://en.wikipedia.org/wiki/Linked_list) are one of Lisp languages' major data structures (http://en.wikipedia.org/wiki/Data_structure), and Lisp source code (http://en.wikipedia.org/wiki/Source_code) is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro (http://en.wikipedia.org/wiki/Macro_%28computer_science%29) systems that allow programmers to create new syntax or even new domain-specific languages (http://en.wikipedia.org/wiki/Domain-specific_language) embedded in Lisp. So Lisps are useful for learning language design, and creating custom languages.

danbaron
16-04-2011, 06:15
Aurel, I suggest -

Look here.

http://www.thinbasic.com/community/showthread.php?11081-M.I.T.-Lisp-Videos&highlight=lisp+videos

Download at least the first video, and watch it. It won't bite you!

:cry: :p

Charles Pegge
16-04-2011, 08:58
I'm still thinking about how LISP could be integrated with BASIC. The parsing rules are a tiny subset of what we need to interpret Basic, so this is no great technical challenge.

Perhaps Lisp could be invoked as a pseudo-procedure:

lisp(...)

then everything between the brackets is parsed using Lisp rules.

naive example:


dim as long a,b,c,d

lisp(
(=d (+ a b c))
)

Charles

zlatkoAB
16-04-2011, 13:20
Im not fascinating by lisp at all, and who know maby really bite
I dont know i still dont find anything useful to me in lisp...
Or i dont know how to use it that will be useful

Charles Pegge
16-04-2011, 17:45
It could be quite a powerful combination with Basic. I think the weakness of lisp is in dealing with the 'C' environment - the grubby business of interfacing DLLs and the operating system in general. On the other hand our dialects of Basic do this very well but are restrictive when attempting more abstract levels of programming.

Charles

zlatkoAB
16-04-2011, 19:41
Charles... your way of understanding things are great.
probably becose of that i like Oxygen:D

danbaron
16-04-2011, 21:02
I can't force you - or, can I?!?!! Ha! Ha! Ha! Ha! Ha! Ha! Ha! :twisted:

zlatkoAB
17-04-2011, 10:04
Dan....
You can't force me becose im on the
->DARK SIDE OF FORCE<-
7161

danbaron
18-04-2011, 07:08
Be very careful, Aurel.
There are powers in this world, which you don't understand.

:(

**********(Nosferatu)
7162

zlatkoAB
18-04-2011, 13:26
Dan this is just SF stories nothing else.....STAR WARS...
What kind of conection have your image - nothing

zlatkoAB
18-04-2011, 13:27
back to topic...
I found BeeLisp but unfortunatly is not freeware.
UfaSoft is not something but i will try!

danbaron
19-04-2011, 07:52
Don't worry, sleep well.

7163