Author Topic: Lisp in Basic  (Read 208068 times)

0 Members and 1 Guest are viewing this topic.

jack

  • Guest
Re: Lisp in Basic
« Reply #975 on: March 26, 2015, 04:25:53 PM »
this is a bit off topic, but speaking about code generation, one very interesting feature of the Maple CAS is the ability to  generate code from Maple Code to a variety of languages, C, C#, Fortran, Java, Javascript, VisualBasic.
it would be awesome to have such a tool to translate code from one language to another.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #976 on: March 26, 2015, 05:20:08 PM »
Oh yes, imagine an IT company's IML (intermediary meta-language) Department with a dozen labs headed by Kevin-Diggins clones each developing its own IL-to-whatever translator for a fair average pay of a hundred kilobucks per capita per annum.  ;D

Seriously, the idea is in fact nothing new; that's how the .NET platform actually works. Almost every .NET scenario can be regenerated into equally functional C# or VB.NET sources. But of course a multi-language implementation is going to be so laborious that noone in his right senses would accept the challenge out of sheer faith in the FSF isms.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #977 on: March 26, 2015, 09:09:51 PM »
In Oxygen terms, this would take the form of a customised compiler, supporting both static and dynamic compiling. Similarly in FBSL, such a scheme would be firmly linked to FBSL's frameworks and future development path.

Would that be a bad idea, do you think?

JRS

  • Guest
Re: Lisp in Basic
« Reply #978 on: March 26, 2015, 09:41:22 PM »
@Charles - Whatever happened to your O2 to C aspirations? Is C header file support it?

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #979 on: March 27, 2015, 12:48:33 AM »
Hi Mike,

I think it's do-able with very little effort, and well worth an exploratory project.


Hi John,

It is still on my list, but I am still working on the language side of O2. It needs to grow organically and I'm seriously contemplating another 5 years of development, to complete the list.

JRS

  • Guest
Re: Lisp in Basic
« Reply #980 on: April 16, 2015, 05:37:02 PM »
Request

I'm trying to put a few like examples together to show the TinyScheme and Perl extension modules and compare them with Script BASIC. What would be a fair / common example that would play in all three environments? I could use some help on defining the criteria and the TinyScheme example. I will do the Script BASIC version and maybe we can make it a group effort for the Perl example.

The goal is to show what makes each language unique and promote its strengths. In the end we should see which tool (language) is best for the job.
« Last Edit: April 16, 2015, 05:48:05 PM by John »

JRS

  • Guest
Re: Lisp in Basic
« Reply #981 on: April 16, 2015, 09:57:28 PM »
Here are the times for getting the prime numbers up to 5000.

Primes in all languages

Perl: 0m0.079s
Code: Perl
  1.        
  2. $n = 5000;
  3. for($i=3;$i<=$n;$i++)
  4. {
  5.     $is_prime = 1;
  6.     for($j=2;$j<=sqrt($i);$j++){
  7.         if($i % $j == 0){
  8.             $is_prime = 0;
  9.             break;
  10.         }
  11.     }
  12.     if($is_prime == 1) {
  13.         print $i." ";
  14.     }
  15. }
  16. print "\n";
  17.  

Script BASIC: 0m0.634s
Code: Script BASIC
  1. FOR n = 2 TO 5000
  2.   FOR k = 2 TO n / 2
  3.     flag = 0
  4.     r = n % k
  5.     IF r = 0 THEN
  6.      flag = 1
  7.      GOTO done
  8.     END IF
  9.   NEXT k
  10.   done:
  11.   IF flag = 0 THEN PRINT n," "
  12. NEXT n
  13. printnl
  14.  

TinyScheme: 0m0.971s
Code: Scheme
  1. (newline)
  2. (display "start")
  3. (newline)
  4.  
  5. (define (seq x)
  6.    (let ((M '()))
  7.      (do ((i 0 (+ i 1)))
  8.          ((> i x))
  9.          (set! M (cons i M))) M ))
  10.  
  11. (define numbers (reverse (seq 4999)))
  12.  
  13. (define (sieve L)
  14.    (let ( ( len (- (length L) 2)) (vec (list->vector L)) )
  15.      (do ((i 2 (+ i 1)))
  16.          ((> i (floor (/ len 2))))
  17.  
  18.          (when (> (vector-ref vec i) 0)
  19.             (do ((j 2 (+ j 1)))
  20.                 ((> (* i j) len))
  21.  
  22.                 (vector-set! vec (* i j) 0)))) vec ))
  23.  
  24. (define (print-vec V)
  25.    (let ((len (vector-length V)) (cnt 0) )
  26.      (do (( i 2 (+ 1 i)))
  27.          (( = i (- len 1)))
  28.          (let (( item (vector-ref V i)))
  29.            (when (not (= item 0))
  30.               (set! cnt (+ 1 cnt))
  31.               (display item)
  32.               (display " ")))) cnt ))
  33.  
  34. (define (main)
  35.   (let ((cnt 0))
  36.    (newline)
  37.    (display "calculating prime-numbers < 5000")  (newline)
  38.    (display "--------------------------------")  (newline)
  39.    (set! cnt (print-vec (sieve numbers)))
  40.    (newline)
  41.    (display "that's it")
  42.    (newline)
  43.    (display cnt) (display "  prime numbers found") ))
  44.  
  45. (main)
  46.  
 

« Last Edit: April 16, 2015, 11:03:39 PM by John »

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #982 on: April 17, 2015, 01:57:45 AM »
Let me throw in an o2 assembler example :)

Code: Text
  1.   includepath "$\inc\"
  2.   include "console.inc"
  3.   sys a
  4.   mov edi,2
  5.   (
  6.     mov esi,edi
  7.     shr esi,1
  8.     mov ecx,2
  9.     (
  10.       cmp ecx,esi : jg exit  'passes prime test
  11.       mov eax,edi : xor edx,edx : div ecx
  12.       (
  13.         cmp edx,0 : jnz exit 'remainder
  14.         jmp fwd ndone        'no remainder, therefore not prime
  15.       )
  16.       inc ecx : repeat
  17.     )
  18.     pushad : a=edi : print " " & a : popad
  19.     ndone:
  20.     inc edi : cmp edi,5000 : jle repeat
  21.   )
  22.   printl "ok"
  23.   waitkey
  24.  

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #983 on: April 17, 2015, 02:40:28 AM »
Hi,

Since none of us seems to be an expert in Perl and/or Scheme, perhaps we should try and find something at RosettaCode.org?

Charles Pegge

  • Guest
Re: Lisp in Basic
« Reply #984 on: April 17, 2015, 03:24:04 AM »
Implementation using o2 projectsA/LeanLisp.

Delightfully stringy and slow :)

Code: OxygenBasic
  1. % UseSystemConsole
  2. includepath "$/inc/"
  3. include console.inc
  4. includepath ""
  5. include LispishUtil.inc
  6.  
  7. print lisp `( eval
  8.  
  9. "primes:" (cr)
  10. ( let primes " c           ; DOWNCOUNT PARAM C
  11.   ( eval
  12.     ( let primes ' 2 ' )   ; LIST WITH STARTING VALUE
  13.    ( let v 3     )        ; FIRST CANDIDATE
  14.     ( let n 1     )        ; LIST INDEX
  15.     ( let d )              ; DIVISOR
  16.     ( eval
  17.       ; CHECK EACH CANDIDATE BY USING PREVIOUS PRIMES AS DIVISORS
  18.       ( set n 1 )
  19.       ( loop ( eval
  20.         ( set d ( getmid primes n 1 ) ) ;GET NEXT PRIME DIVISOR
  21.           ( if d
  22.             ( )
  23.             ( eval ( setmid primes 0 0 v ) (exit) ) ; APPEND
  24.           )
  25.           ( if ( == 0 ( mod v d ) ) (exit) )
  26.           ( incr n ) ; NEXT PRIME D
  27.       ) ) ; eval loop
  28.       ( incr v ) ( iter c ) ; NEXT CANDIDATE
  29.     )
  30.     primes ; EXPOSE COMPLETED LIST
  31.   )
  32. ")
  33.  
  34. ( primes 1000 ) (cr)
  35. ) ;eval
  36.  
  37. ` 'end of src
  38.  
  39. waitkey
  40.  

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #985 on: April 17, 2015, 04:41:38 AM »
Hi Charles,

What are the benchmarks for these two scripts on your PC?

Peter

  • Guest
Re: Lisp in Basic
« Reply #986 on: April 17, 2015, 05:49:43 AM »
Quote
Let me throw in an o2 assembler example

only the author knows what that means. ( ), repeat, fwd, exit, and so on!
a small tutorial would be good. everything in small steps might tell us the mystery.

Mike Lobanovsky

  • Guest
Re: Lisp in Basic
« Reply #987 on: April 17, 2015, 07:50:20 AM »
only the author knows what that means. ( ), repeat, fwd, exit, and so on!
a small tutorial would be good. everything in small steps might tell us the mystery.




 :D

Peter

  • Guest
Re: Lisp in Basic
« Reply #988 on: April 17, 2015, 08:07:47 AM »
Thanks Mike, that you have chosen the good side!

JRS

  • Guest
Re: Lisp in Basic
« Reply #989 on: April 17, 2015, 08:14:27 AM »
@Charles - Both prime examples ran under Wine. The asm version was instant with a slight delay for the lean version. I don't have the timer utility installed on Wine yet but will sometime today.