Author Topic: Lisp in Basic  (Read 208119 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
Re: Lisp in Basic
« Reply #195 on: August 06, 2014, 11:38:18 AM »
I'm not sure if this is working as you expected but it prints about 30 or so GC messages and waits. If I press the return key, it does it again. No way to get out other than a CTRL C.

@MIKE - Can you explain what this script is doing?


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #196 on: August 06, 2014, 12:03:37 PM »
It defines a recursive function that checks its argument (x) for being less than or equal to

Code: [Select]
1000*1000*1000*1000*1000*1000*1000*1000*1000*1000
which is actually 10 to the 29th power. If its argument is less than or equal to this value, it calls its own self (i.e. recursively) with an argument of (x+1). The newly called instance checks its argument which is already (x+1) for being LEQ than 10E+29. If it's still LEQ, it calls its own self again with ((x+1)+1) and so forth, until ((x+1)...+n) is 10E+29 + 1 whereupon it exits.

This is essentially the same as

Code: [Select]
rectest 1

sub rectest (x)
  if x <= 1000*1000*1000*1000*1000*1000*1000*1000*1000*1000 then
    rectest x+1
  end if
end sub

in BASIC.

My FBSL LISP is running this code for 28 minutes already printing a column of GC START GC DONE's on and on. But the FBSL process memory is increasing slowly but steadily, yes. So there may still be a memleak somewhere. Perhaps SB is just a little more susceptible to it. I'll look into it later on.

Now, your assumption about IF PVALUE<>NUMBER OR QTYPE<>NUMBER THEN wasn't correct. This IF block must be commented out in both subprocedures. Also the comparison sign in DoBgr was wrong initially so the bug migrated to its DoLss derivative. So please change your existing subprocedures to the following to make < and > comparisons work properly:

Code: [Select]
:DoBgr
CTYPE=QTYPE
CVALUE=QVALUE
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Cdr
BSD=BSD+1
GOSUB RregtoPreg
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoQreg
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoPreg
IF PTYPE<>NUMBER OR QTYPE<>NUMBER THEN
PRINT "ERROR: IN >\n"
GOTO HandleError
END IF
'IF PVALUE<>NUMBER OR QTYPE<>NUMBER THEN
' PRINT "ERROR: IN >\n"
' GOTO HandleError
'END IF
IF PVALUE<QVALUE THEN
RTYPE=BOOLEANT
RVALUE=TRUE
BSD=BSD-1
RETURN
END IF
RTYPE=NULL
RVALUE=FALSE
BSD=BSD-1
RETURN

:DoLss
CTYPE=QTYPE
CVALUE=QVALUE
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Cdr
BSD=BSD+1
GOSUB RregtoPreg
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoQreg
PTYPE=CTYPE
PVALUE=CVALUE
BSD=BSD+1
GOSUB Car
BSD=BSD+1
GOSUB RregtoPreg
IF PTYPE<>NUMBER OR QTYPE<>NUMBER THEN
PRINT "ERROR: IN <\n"
GOTO HandleError
END IF
'IF PVALUE<>NUMBER OR QTYPE<>NUMBER THEN
' PRINT "ERROR: IN <\n"
' GOTO HandleError
'END IF
IF PVALUE>QVALUE THEN
RTYPE=BOOLEANT
RVALUE=TRUE
BSD=BSD-1
RETURN
END IF
RTYPE=NULL
RVALUE=FALSE
BSD=BSD-1
RETURN

JRS

  • Guest
Re: Lisp in Basic
« Reply #197 on: August 06, 2014, 12:15:30 PM »
Thanks Mike!

I'll make the corrections to the SBLisp source and get it posted on the repository.

What I might be seeing is the limit I set in the basic.conf file.

Code: [Select]
maxlevel 29666

I might set it to zero (no checks) and see if it blows up. (seg fault)

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #198 on: August 06, 2014, 12:23:58 PM »
Hehe actually I don't like the "666" - I'm a believer. And my Windows scriba.exe is working without a config file. :)

JRS

  • Guest
Re: Lisp in Basic
« Reply #199 on: August 06, 2014, 12:33:03 PM »
You are correct. scriba doesn't require a basic.conf file to run. SB has default internal settings if a basic.conf can't be found or doesn't exist. The main reason I use a basic.conf is for the IMPORT/INCLUDE statement (ext. modules) to find the SB include and modules directory.


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #200 on: August 06, 2014, 12:47:19 PM »
Understood.

Now an update on scriba.exe+rectest.lisp. No memory leak at all - it prints the GC START GC DONE column smoothly on and on without interruptions. The memory pool of approx. 4.5MB stays as solid as a rock. :)

JRS

  • Guest
Re: Lisp in Basic
« Reply #201 on: August 06, 2014, 12:57:09 PM »
It doesn't seem to have any memory leaks on the Linux version of SBLisp. Memory and the 100% CPU on one core remained consistent for over 15 minutes. I set maxlevel 0 to solve my premature exit issue.

.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #202 on: August 06, 2014, 01:12:52 PM »
This is very good - SB is consistent and LISP garbage collection is faultless.

Unfortunately this signals some slight internal memory leak specific to FBSL. :(

[UPD] But I know where it comes from. This entire program runs exclusively at the global level. But FBSL's internal GC can be triggered only at the points when FBSL exits from a lower level sub-script (scope), e.g. a user Namespace, Sub, Function, Property, Method, Overloaded Operator of a class instance, DynAsm or DynC block. It worked for years and I guess I'm not going to change it for the sake of a lone lisp.fbs script. It seems more reasonable to change the script's garbage collector into a genuine Sub instead. This way its automatic execution by the LISP interpreter will trigger concurrent garbage collection on the FBSL server side.

So I may sleep peacefully. :)
« Last Edit: August 06, 2014, 01:29:39 PM by Mike Lobanovsky »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #203 on: August 07, 2014, 01:12:41 AM »
John,

I wasn't correct about not being able to move the cursor to a new line while printing. The intrinsic newline procedure will do just that.

Consider the following sequence of procedures in a lambda (that's LISP lingo for "user-defined function"):

Code: [Select]
(print 'A) (newline) (print 'B) (newline)
It will print A and B on separate lines as shown in the picture. The trailing T is the result - return code - of overall evaluation (LISP lingo for "execution").

However the issue with printable spaces remains open.

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #204 on: August 07, 2014, 01:21:26 AM »
Good news!

Sure glad you're steering this boat.  8)

I started adding issues to the Bitbucket issue tracker if you can do the same with what you find.


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #205 on: August 07, 2014, 01:28:45 AM »
Sure glad you're steering this boat.

I'm intrigued by Charles' variadic average lambda challenge. Standard Scheme offers several options to denote a list of arbitrary length but I haven't yet figured out how to mimic it in SB/FBSL LISP.

JRS

  • Guest
Re: Lisp in Basic
« Reply #206 on: August 07, 2014, 01:47:57 AM »
I'm still trying to figure out why (load (quote FF.SCM)) doesn't work in MIT/GNU Scheme.

Signing out. Zzzzzz
« Last Edit: August 07, 2014, 01:57:32 AM by John »

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #207 on: August 07, 2014, 02:57:22 AM »
Hi   John , Mike ..


I think in Racket Scheme and Bigloo the syntax is    (load "something.scm")    ?????

If this Scheme has "apply"  :

on a list :

(define (average L)
 (let ((x (length L)))
   (if (= 0 x)
     0
     (/ (apply + L) x ))))

(intercepts the empty list , avoiding a division by zero ).

best Rob

oops : somewhat incorrect to use 0 as a result  -- there is no result :

(define (average L)
 (let ((x (length L)))
   (if (= 0 x)
     (print "the list is empty , there can be no result")
     (/ (apply + L) x ))))

(or something alike : you can give back "nil" (the Lisp symbol for "the nothing" and false ) too )...

you can even map a condition first over the list examining if it are numbers

something as   if ( apply + on map::if the element is a number -> 0 else 1 ) =0 then the list is composed of numbers exclusively  ... etc etc ...
« Last Edit: August 07, 2014, 03:11:11 AM by RobbeK »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #208 on: August 07, 2014, 04:34:05 AM »
@John:

I suggested a tip on a working alternative to define literals in an expression. Please try (load 'FF.SCM) for a change and see what happens. But the both alternatives should work in standard Scheme equally well.


@Rob:

Hi,

(define (something something_else)) is not proper syntax for this LISP. Proper expressions would be (define something something_else), (define something (expression)), and (define something (lambda (optional_arg) ... )). But I'll try to blend your suggestions to this LISP's syntax. In the meantime, please see below.


@Charles:

Hi,

This is the best I could do so far. It is absolutely ugly but it works and it is variadic. I will also try to abridge Rob's suggestions though he simply doesn't realise how far the intrinsic flexibility of standard Scheme's syntax is from the Spartan minimality of SB/FBSL LISP.

So here's the Average.lisp script. It's runnable in FBSL LISP and both reincarnations of SBLisp:

Code: [Select]
(define accum 0)

(define average
  (lambda (input)
    (for-each (lambda (x) (set! accum (+ accum x))) input)
      (print (set! accum (/ accum (length input)))) (newline)
  )
)

(define args (list 1 2 3 4 5))

(average args)

and below is a snapshot with its results. Comments are given directly in the picture because SB/FBSL LISP doesn't support embedded comments yet.

.
« Last Edit: August 07, 2014, 04:56:37 AM by Mike Lobanovsky »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #209 on: August 07, 2014, 05:11:39 AM »
[UPD]

Trial and error shows that the above script can be successfully reduced to the following, which eliminates effectively the need for an ARGS list:

Code: [Select]
(define accum 0)

(define average
  (lambda (input)
    (for-each (lambda (x) (set! accum (+ accum x))) input)
      (print (set! accum (/ accum (length input)))) (newline)
  )
)

(average (list 0 1 2 3 4 5 6 7 8 9))