(archive 'newLISPer)

January 12, 2008

Lambdalator: the story so far

Filed under: newLISP — newlisper @ 16:20

One of the fun things about my current experiment, the Lambdalator (a simple script that provides the internet with a 24/7 online newLISP console) is that I left a call to the following function in the script. I’d used this function when I’d first uploaded the script for testing:

(define (log-input x)
    (append-file log-file-name
                (date-value) 0 "%Y-%m-%d %H:%M:%S") { }
            (get-ip) { } x "\n")))

So whenever anyone types anything and clicks the ‘evaluate’ button, the date, time, their IP address, and what they typed are saved in a log file. So by looking at the log it’s more or less possible to watch people arrive, enter stuff, get annoyed, and go away. This has provided a lot of entertainment – and some education – over the last few weeks, and I’ll share some of it here.

2008-01-03 18:40:20 163.453.357.176 hello

(All IP addresses have been scrambled in this post.)

The big drawback of the Lambdalator is that, as with any programming language, if you don’t get the format exactly right, the result will be, at the very least, unexpected. newLISP doesn’t pretend to understand English, and the Lambdalator isn’t an exercise in artificial intelligence or natural language parsing. It’s just a simple online calculator-style utility expecting expressions using newLISP syntax; there’s only 100 or so lines of code, and a chunk of that is HTML.

But I wish I’d added some extra code to handle input like this:

2008-01-03 15:06:48 33.453.30.235 how are you doing?
2008-01-03 15:07:14 33.453.30.235 What is the purpose of this?

or to respond to ‘calculations’ like this:

2008-01-03 12:08:24 Today I am going to work very hard

2008-01-04 21:48:59 93.453.398.228 sausages

2008-01-05 10:08:23 63.453.31.191 poop

Of the people that have actually tried to use it as a calculator, many have of course been thrown by the postfix notation, the compulsory parentheses, and the need for white space to separate functions and arguments. With no knowledge of what should be typed, and a reluctance to click the ‘help’ button, newLISP’s responses are entertaining, enigmatic, irritating, or just baffling. Here are some examples – I’ve added the Lambdalator’s replies so that you can sympathize – or not – with the questioner:

2008-01-06 22:43:06 83.453.359.133 (+22)
invalid function : (22)

2008-01-05 18:28:54 153.453.38.114 (+2 2)
illegal parameter type : 2

2008-01-04 12:42:33 63.453.381.231 (2 -3 2 2 6)
illegal parameter type : -3

2008-01-06 19:46:23 76.73.453.332 + 2 2

2008-01-06 21:11:36 73.453.303.239 61-8

2008-01-05 04:01:22 add 5 65 46

2008-01-05 02:42:53 33.453.39.213 2*5

2008-01-04 12:41:39 63.453.381.231 4 plus 2

2008-01-03 13:28:50 33.453.332.66 cos(x) + sin(y)
invalid function : (x)

2008-01-07 03:56:41 32.423.242.38 ( 6% of 70)
illegal parameter type : %

Many were confused by the fact that the Lambdalator returns the value of the last expression evaluated, but only the last. So + 2 2 returns the last 2 – not the expected sum.

Here are some optimistic entries, where people have expected more from my efforts than I could deliver:

2008-01-03 15:18:06 143.453.329.143 2x+3=40

2008-01-03 15:18:48 143.453.329.143 x=2y+4

2008-01-05 16:52:29 56+33*x=0

2008-01-04 12:39:08 73.453.33.175 x2\y=9

2008-01-03 05:29:36 68.73.453.30 1+x=9

Luckily newLISP refrains from offering an opinion on such weighty matters. One day I’ll write something that solves equations.

Some people have a different idea about what parentheses are:

2008-01-03 18:06:31 68.453.37.26 [2.3]+{4[6.3]}

2008-01-04 13:21:50 193.453.355.48 [ + 2 2 ]

One problem that I had anticipated is that in newLISP the standard arithmetic operators such as ‘+’ and ‘-‘ are integer only, and you use the ‘add’ and ‘sub’ equivalents for floating-point operations. I’ve got used to this, and there’s an easy way to re-define ‘+’ to do the job of ‘add’, but I decided to keep the behaviour as close to the documented default as possible. But it’s a pity that a good attempt like the following should have received the wrong answer:

2008-01-08 00:01:49 75.453.32.16 (+ (+ 1.234 91.3) (+ 1.234 91.3))

A few Lisp speakers have visited the site, and they obviously know the basics, although the whole thing is probably much too simplistic and toy-like for the Common Lisp folks. I seem to remember that ‘car’ is the equivalent of newLISP’s ‘first’ function, and it’s obviously a favourite (but not available by default in newLISP):

2008-01-07 03:25:17 72.453.32.16 (car '(a b c))
invalid function : (car '(a b c))

2008-01-03 19:40:50 83.453.305.64 (car (cons 1 "a" 3.45  'foo))
invalid function : (car (cons 1 "a" 3.45 'foo))

2008-01-07 03:25:01 73.453.32.16 (cons '(a b c))
((a b c))

2008-01-10 20:41:37 63.453.379.30 (foldr list 'end '(a b c d))
invalid function : (foldr list 'end '(a b c d))

I’ve not heard of ‘foldr’.

But here’s a fun entry that set me thinking:

2008-01-10 20:47:45 65.453.379.30 (apply (lambda (x) (* x 2)) '(1 2 3))

Why does this return 2 – and not 6, for example, which I might have expected, although I would have used ‘map’:

(map (lambda (x) (* x 2)) '(1 2 3))
(2 4 6)

The other big drawback with the whole idea of the Lambdalator is that it’s not possible to have a persistent newLISP interpreter online in this way. Well, it’s probably possible, but I know that my current host doesn’t allow persistent processes, and I expect there are other issues to think about. At the moment the web page gives the illusion of some persistence, with the ‘paper tape’ feature of a typical desktop calculator keeping a record of what’s been processed, but of course in reality every time an expression is submitted a new session is started with no record of any previous entries.

I think I’ll keep the Lambdalator online for a few more weeks, since it’s interesting to watch what people make of it, and I make use of it myself occasionally. I’ve yet to see anyone trying to hack the security, which will be interesting – and possibly worrying – to watch.


Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: