Author Topic: Lisp in Basic  (Read 208351 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #585 on: August 20, 2014, 09:27:16 AM »
Don't mention it, John,

It was my pleasure to see it working in my console too. :)

My PC is just a bit faster so I'm getting some .925 sec or so. That's practically equal.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #586 on: August 20, 2014, 10:16:32 AM »
It takes FBSL's DynC almost 18 seconds to calc (4, 1)... :(

But the good thing is it doesn't exhaust the stack though.  ???

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #587 on: August 20, 2014, 10:37:16 AM »
Seems that C is a bit more forgiving.  8)

JRS

  • Guest
Re: Lisp in Basic
« Reply #588 on: August 20, 2014, 10:40:10 AM »
Quote from: Arthur
Dear John,

> Mike Wrote:
>
> There is absolutely no functionality whatsoever implemented in this QB
> 4.5 code that would allow the *QB program stack* to be restored in case
> Lisp-in-Basic hits an error while one of its many recursive GoSub's is
> in deep recursion into itself, its siblings and children, and its parent
> such as LispPrint or especially LispEval into the bargain.

Ah, but there is: return.  If you look for the label ClearStackLoop in the
original code, you'll see that it repeatedly returns.  That is the point,
to clear the stack.  The variable BSD stands for Basic Stack Depth.

-Arthur



==============================================================
Arthur Nunes-Harwitt
Computer Science Department, Rochester Institute of Technology

RobbeK

  • Guest
Re: Lisp in Basic
« Reply #589 on: August 20, 2014, 01:07:48 PM »
Hi all,

FWIIW  -- the GCL compiler gives the message it converted the recursion (the Ackerman) into iterations.

Added a few useful (?) macro's ..  and seq (seq 6)  -> ( 1 ... 6) while range does (0 ... 5)  -- normal Lisp indexbase 0.
(this is important when using the sequence as the number of "iterations" of a certain function )   -- i mean, you can not 0 times iterate something :  in this case it results in 1/0 ::)
example attached :  (as an example , because by memoizing a previous result this can be speeded up a very lot - the sequences are recalculated every time ).

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

(define 1+
   (lambda (x) (+ 1 x)))

(define 1-
   (lambda (x) (- x 1)))

(define println
   (lambda (s)
     (print s) (newline)))


(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))

(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))

(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))


(define seq
    (lambda (x)
      (reverse (make-listx 1  (1+ x) '() ))))

;;----------------------------tests -- remove from macro.scm


(define 3eta-1
   (lambda (x)
     (apply + (map (lambda (x) (/ 1 x)) (seq x)))))

(define print3
   (lambda (x)
     (print (3eta-1 x))
     (newline)))

(define tst
   (lambda (x)
     (map print3 (seq x)) T ))

(define main
(lambda()
(iterate 'newline 10)
(println '"First 50 iterations of Zeta(1)")
(println '"-------------------------------")
(println '" ")
(println '"without memoizing things !")
(newline)
(tst 50)
(newline)
(println '"........finished.........")
))

(main)
--------------------------------------------------------------------------------------------------------

best, Rob   
--  forgot, thanks for the LispOS link, John  -- unaware about it


 
« Last Edit: August 20, 2014, 01:25:32 PM by RobbeK »

JRS

  • Guest
Re: Lisp in Basic
« Reply #590 on: August 20, 2014, 01:14:24 PM »
Thanks Rob!

Code: [Select]
jrs@laptop:~/sb/sb22/sblisp$ time scriba lisp.sb rob_zeta.scm
SBLisp - Scheme BASIC Lisp

(define 1+
   (lambda (x) (+ 1 x)))
1+
(define 1-
   (lambda (x) (- x 1)))
1-
(define println
   (lambda (s)
     (print s) (newline)))
PRINTLN
(define make-listx
     (lambda (i x L)
      (if (= i x) L
          (make-listx (+ i 1) x (cons i L)))))
MAKE-LISTX
(define range
  (lambda (x)
    (reverse (make-listx 0 x '() ))))
RANGE
(define iterate
  (lambda (op it)
    (map (eval op) (range it))
  T ))
ITERATE
(define seq
    (lambda (x)
      (reverse (make-listx 1  (1+ x) '() ))))
SEQ
(define 3eta-1
   (lambda (x)
     (apply + (map (lambda (x) (/ 1 x)) (seq x)))))
3ETA-1
(define print3
   (lambda (x)
     (print (3eta-1 x))
     (newline)))
PRINT3
(define tst
   (lambda (x)
     (map print3 (seq x)) T ))
TST
(define main
(lambda()
(iterate 'newline 10)
(println '"First 50 iterations of Zeta(1)")
(println '"-------------------------------")
(println '" ")
(println '"without memoizing things !")
(newline)
(tst 50)
(newline)
(println '"........finished.........")
))
MAIN
(main)










FIRST 50 ITERATIONS OF ZETA(1)
-------------------------------
 
WITHOUT MEMOIZING THINGS !

1
1.500000
1.833333
2.083333
2.283333
2.450000
2.592857
2.717857
2.828968
2.928968
3.019877
3.103211
3.180134
3.251562
3.318229
3.380729
3.439553
3.495108
3.547740
3.597740
3.645359
3.690813
3.734292
3.775958
3.815958
3.854420
3.891457
3.927171
3.961654
3.994987
4.027245
4.058495
4.088798
4.118210
4.146781
4.174559
4.201586
4.227902
4.253543
4.278543
4.302933
4.326743
4.349999
4.372726
4.394948
4.416687
4.437964
4.458797
4.479205
4.499205

........FINISHED.........
T
(quit)

real 0m2.505s
user 0m2.468s
sys 0m0.028s
jrs@laptop:~/sb/sb22/sblisp$

JRS

  • Guest
Re: Lisp in Basic
« Reply #591 on: August 20, 2014, 03:01:41 PM »
Message sent with images.

Arthur has a link to this thread. His contribution and well as yours is much appreciated.

Thanks to all that have found time to move this along.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #592 on: August 20, 2014, 03:37:19 PM »
Too bad.

I have just deleted both messages.

I was wrong. His scheme would, and actually does, work. In QuickBasic, that is; actually impossible to mimic this behavior with the existing vocabulary in SB, FBSL, or any other interpreter that I know of. We would have to open the hoods and get our hands dirty with our engines because this functionality can only be implemented at the underlying C level.

I am so sorry to have been so damn blind, dumb, hard-nosed, and so mouthy at that.  :-[

Shame on me. Please let Mr Arthur Nunes-Harwitt know that I'm hereby withdrawing all my ungrounded criticisms and apologize for my big mouth.


P.S. This doesn't however change our own plan in the least. Orderly bailout from recursive functions in response to a global flag is our only choice. We haven't got anything that would behave like RETURN Label in our environments.

JRS

  • Guest
Re: Lisp in Basic
« Reply #593 on: August 20, 2014, 03:47:24 PM »
While you're in that sensitive mood, why do you think SB is unable to support the stack handling under the covers with GOTO to another GOSUB and have it return? All Arthur did was shave off an extra return and expand his existing GOSUB routine. If I'm wrong, I'm more than willing to invest the time to understand what is truly going on and if it is a problem in SB. From what I'm seeing SBLisp works.

On the other hand we agreed that the end goal was to create a C extension of this in our respective languages. Without the work that you and I have done, SBLisp is a console mode Scheme interpretor which could be used as a learning tool for Lisp. I don't see it being a contender to a real Lisp in it's current form. Once an extension module in C is accomplished, that's when the game changes.
« Last Edit: August 20, 2014, 06:13:12 PM by John »

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #594 on: August 20, 2014, 04:29:13 PM »
John,

XBLisp is currently working perfectly stable because the global flag and emergency returns have been already fully implemented. The GoSub's yet remaining in LispEval also obey this flag and use EXIT SUB instead of RETURN to exit from their LispEval parent to the main loop. It is already working, and note also that we are talking about exception conditions that occur very seldom in our yet non-existent programs.

My proxy dispute with Arthur was somewhat scholastic and pertained to the QB code more than the one we're using now. It doesn't change our plans in the least. And I didn't say we had to add this RETURN Label functionality; we don't need it so urgently. What I really meant was it would be kinda cool to have the same in our interpreters, is all.

Concerning "GOTO to another GOSUB", it wouldn't be a proper vision of the problem. You may not goto to another sub freely while in recursion. For you to have the right to goto, the both ends of the jump must be at the same recursion depth level or the stack will get disbalanced sooner or later, which will end up in an inevitable crash.

It is rather a RETURN deal where the original point (address) of return is substituted with another address one recursion level up the current stack frame. But forget it. This isn't imperatively needed for SBLisp.

JRS

  • Guest
Re: Lisp in Basic
« Reply #595 on: August 20, 2014, 04:53:54 PM »
Will you be releasing something soon?


Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #596 on: August 20, 2014, 05:05:59 PM »
Tomorrow evening my time (morning, your time). You will have it fasting instead of your usual morning coffee and first smoke. :)

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #597 on: August 20, 2014, 05:11:24 PM »
Hmmmm... My Ackermann handcoded in DynAsm is only some 2 seconds faster than DynC. ???

I don't know how it can be seeing John's 3 sec CBASIC benchmark. What optimizations are you using in your stock GCC, John?



@Charles:

Can you somehow comment on these strange phenomena, please?

.

JRS

  • Guest
Re: Lisp in Basic
« Reply #598 on: August 20, 2014, 05:34:31 PM »
Quote
What optimizations are you using in your stock GCC, John?

O3

Looking forward to seeing the new version of SBLisp. Are all the GOSUB/GOTO's gone now?
« Last Edit: August 20, 2014, 05:51:00 PM by John »

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #599 on: August 20, 2014, 06:14:36 PM »
I confirm Mike's timing with o2 asm. - Time enough to down a cup of jasmine tea, anyway :)

Code: [Select]
function AckA(sys m,n) as sys

return call A m,n

.A
mov ecx,[esp+4] 'm
mov edx,[esp+8] 'n
(
  cmp ecx,0
  jg exit       'm>0 skip
  inc edx       'n+1
  mov eax,edx   'ret n+`
  ret 8
)
(
  cmp edx,0     '
  jg exit       'n>0 skip
  dec ecx       'm-1
  call A ecx,1  'm-1,1
  ret 8
)
dec edx         'm,n-1
call A ecx,edx  't
mov ecx,[esp+4] 'm reload
dec ecx         'm-1
call A ecx,eax  ' m-1, t
ret 8

end function

AckA 4,1 '65533