Author Topic: Updating OxyScheme  (Read 23801 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: Updating OxyScheme
« Reply #45 on: November 25, 2019, 10:17:48 AM »
This simplified version of when works in oxycheme, so macros are basically ok:

Code: [Select]
(macro when (lambda(a b) (cond (a b) ) ) )

(when (> 2 1) 'greater )


Mike Lobanovsky

  • Guest
Re: Updating OxyScheme
« Reply #46 on: November 25, 2019, 07:45:33 PM »
Roland,

The nano-/oxyscheme code was based (with some amendments of mine) on a slightly different, more precise and arguably a little faster, version 0.85k4 of same:

/*
 *      ---------- Mini-Scheme Interpreter Version 0.85 ----------
 *
 *                coded by Atsushi Moriwaki (11/5/1989)
 *
 *            E-MAIL :  moriwaki@kurims.kurims.kyoto-u.ac.jp
 *
 *               THIS SOFTWARE IS IN THE PUBLIC DOMAIN
 *               ------------------------------------
 * This software is completely free to copy, modify and/or re-distribute.
 * But I would appreciate it if you left my name on the code as the author.
 *
 */
/*--
 *
 *  This version has been modified by R.C. Secrist.
 *
 *  Mini-Scheme is now maintained by Akira KIDA.
 *
 *  This is a revised and modified version by Akira KIDA.
 *   current version is 0.85k4 (15 May 1994)
 *
 *  Please send suggestions, bug reports and/or requests to:
 *      <SDI00379@niftyserve.or.jp>
 *--
 */


The code then got promoted by Dimitrious Souflis yet further to 32-bit only and still public domain v1.41 that became completely thread safe:

/* T I N Y S C H E M E    1 . 4 1
 *   Dimitrios Souflis (dsouflis@acm.org)
 *   Based on MiniScheme (original credits follow)
 * (MINISCM)               coded by Atsushi Moriwaki (11/5/1989)
 * (MINISCM)           E-MAIL :  moriwaki@kurims.kurims.kyoto-u.ac.jp
 * (MINISCM) This version has been modified by R.C. Secrist.
 * (MINISCM)
 * (MINISCM) Mini-Scheme is now maintained by Akira KIDA.
 * (MINISCM)
 * (MINISCM) This is a revised and modified version by Akira KIDA.
 * (MINISCM)    current version is 0.85k4 (15 May 1994)
 *
 */


And (hopefully) finally, John had me sweet-talked into extending that later tinyscheme code to 64 bits, which we did (hopefully again) successfully totally outside the framework of OxygenBasic forum. :D


Charles,

But regretfully, your simpler implementation fails miserably in FBSL C nanoscheme, original C minischeme and multithreaded 32-bit tinyscheme complaining invariably of insufficient arguments/parameters to the macro. Which, alas, invalidates your implementation as a reference. :-[

Charles Pegge

  • Guest
Re: Updating OxyScheme
« Reply #47 on: November 26, 2019, 02:54:52 AM »
Hi Mike,

I was just trying to isolate the problem. It appears to be in the unquote procedures ','

this wont work:

Code: [Select]
`(list ,(+ 1 2) 4)

Mike Lobanovsky

  • Guest
Re: Updating OxyScheme
« Reply #48 on: November 26, 2019, 08:09:33 AM »
Yes Charles,

Your diagnosis seems correct. Oxyscheme doesn't recognize unquote flagging it erroneously as an unbound variable.

Quote/unquote should just render the entire statement that follows, as a string literal, rather than execute that statement immediately. They are part of macro notation used chiefly to embed macro implementations in Scheme libraries. Once the library is loaded, and its embedded macro implementations, unquoted, executed where necessary and mapped in the process memory, the respective macros may be used by their names as ordinary pieces of executable code throughout a Scheme program.
« Last Edit: November 26, 2019, 08:24:52 AM by Mike Lobanovsky »

Arnold

  • Guest
Re: Updating OxyScheme
« Reply #49 on: November 26, 2019, 08:24:21 AM »
Perhaps backquote does not work correctly?
 `(+ 2 3)   expected: (+ 2 3)
Error: unable to cdr a non-pair element

This is also a nice construct:
 `,(+ 2 3)  exptected: 5

Mike Lobanovsky

  • Guest
Re: Updating OxyScheme
« Reply #50 on: November 26, 2019, 08:35:08 AM »
Yes Roland,

In both cases, FBSL nanoscheme produces the effects as you'd expect. But oxyscheme regretfully falters, which means not only unquote but also quasiquote fail in the O2 environment.

Cutting it short, oxyscheme is in need of serious overhaul even in an older Oxygen before it ever goes 64 bits. :(

Charles Pegge

  • Guest
Re: Updating OxyScheme
« Reply #51 on: November 26, 2019, 07:40:17 PM »
I'm giving it the full sweep. I've found a few indexing anomalies so far, which might explain the quote/unqute problems.

Charles Pegge

  • Guest
Re: Updating OxyScheme
« Reply #52 on: November 27, 2019, 07:55:59 AM »
How might you bind Scheme to Windows and other APIS?

Mike Lobanovsky

  • Guest
Re: Updating OxyScheme
« Reply #53 on: November 27, 2019, 08:37:52 AM »
There are a few Lisps around that have bindings to Windows graphics and API. We can look up and mimic their semantics to keep up the letter and spirit of this near-esoteric language cluster.

When I'm looking into those weird Scheme-ish scripts, it feels as if I'm trying to follow simplified Chinese. ;D

Arnold

  • Guest
Re: Updating OxyScheme
« Reply #54 on: December 05, 2019, 02:04:41 AM »
Hi Mike,

is there a way to check some test cases with miniscm.exe / o2scm.o2bas? Due to my lack of knowledge, I currently do this:

Code: [Select]
;; simple test cases

(define CheckResult
  (lambda (num  expected)
     (display "Test ")
     (display num)
     (display " Expected: ")
     (display expected)
     (newline)
     ))

; (display ", result: ")
; (display result)

...


Is there a way to store e.g. the result of Test 1 (#CLOSURE) or the results of the other tests in a variable and compare this with the expected value? I just want to show the differences. This would save some time.

Roland
« Last Edit: December 07, 2019, 11:35:33 AM by Arnold »

Arnold

  • Guest
Re: Updating OxyScheme
« Reply #55 on: December 05, 2019, 06:05:36 AM »
In the meantime I found a slightly better solution:

Code: [Select]
;; simple test cases

(define result)

(define CheckResult
  (lambda (num  result expected)
       (if (equal? result expected ) (begin (display "Test: ")
                                            (display num) (display " ok "))
         (begin
           (display "Test ") (display num) (display ", result: ") (display result)
           (display " Expected: ") (display expected)
           (newline)))
     ))

...

« Last Edit: December 07, 2019, 11:36:54 AM by Arnold »

Mike Lobanovsky

  • Guest
Re: Updating OxyScheme
« Reply #56 on: December 06, 2019, 02:18:15 AM »
Hi Roland,

In fact, there are many relatively simple ready-made unit test suites for Scheme, e.g. this one. Just load The Code section as an .scm file (it contains the suite's base defines) and then follow the instructions to actually design and run simple unit tests. The test suite syntax should be fully compatible with oxy-/nano-/mini-/tiny-/Schemes. :)

Arnold

  • Guest
Re: Updating OxyScheme
« Reply #57 on: December 07, 2019, 12:19:34 PM »
Thank you Mike for the link. I will certainly investigate more about this topic. For the moment I am applying a very simple approach which only checks the results:

Code: [Select]
;; simple test cases

(define TestResult)
(define tmpTestResult)
(define FailedCases)
(define Counter 0)

(define CheckResult
  (lambda (num  TestResult Expected)
       (if (equal? TestResult Expected )
          (begin (for-each display (list "Test: " num " ok ")))
        ;else
          (begin
             (for-each display (list "Test: " num ", Result: " TestResult " Expected: " Expected))
             (newline)
             (set! Counter (+ Counter 1))
             (set! FailedCases (append FailedCases (list num TestResult Expected))))
       
     )))

 
(define ReportFailures
  (lambda (Counter)
     (if (= 0 Counter)
        (display "All Tests passed OK")
     ;else
        (begin
        (display Counter) (display " Test(s) failed")
        (newline)
        (display FailedCases)
        (newline)
      ))))
   
   
;;; lambda
;;;; syntax:  (lambda formals body)

;1
(set! tmpTestResult `,(lambda (x) (+ x x)))       ;(CheckResult  1   TestResult  `"#<CLOSURE>" )
(set! TestResult `,(closure? tmpTestResult))      (CheckResult  1   TestResult  `#t )

;2
(set! TestResult `,((lambda (x) (+ x x)) 4))      (CheckResult  2   TestResult  8 )

;3
(define reverse-subtract
  (lambda (x y) (- y x)))
(set! TestResult `,(reverse-subtract 7 10))       (CheckResult  3  TestResult 3 )

;4
(define add4
  (let ((x 4))
    (lambda (y) (+ x y))))
(set! TestResult `,(add4 6))                      (CheckResult  4  TestResult 10 )

;5
(set! TestResult `,((lambda x x)
  3 4 5 6))                                       (CheckResult  5  TestResult '(3 4 5 6) )

;6
(set! TestResult `,((lambda (x y . z) z)
  3 4 5 6))                                       (CheckResult  6  TestResult '(5 6) )

;7
(set! TestResult `,(= 10 0))                      (CheckResult  7 TestResult `#f)

;Test function
;8
(define factorial
  (lambda (n)
    (let fact ((i n))
      (if (= i 0)
          1
          (* i (fact (- i 1)))))))
(set! TestResult `,(factorial 12))                (CheckResult  8  TestResult 479001600 )


(newline)
(ReportFailures Counter)
(newline)
(display "End of tests")

When I know more about Scheme I would like to format the output of failed cases.

I noticed that miniscm.c of my reply #44 does not work correctly with applying the 'do' macro due to a missing gensym procedure. Therefore I added OP_GENSYM and autogen() of o2scm.o2bas and updated the attachment of reply #44. I have also created a msinit.scm with some more definitions, as miniscm does not include all the capabilities of o2scm. But it is interesting to compare miniscm.c with o2scm.o2bas and see all the items which are missing.
« Last Edit: December 09, 2019, 07:09:57 AM by Arnold »

Mike Lobanovsky

  • Guest
Re: Updating OxyScheme
« Reply #58 on: December 07, 2019, 05:28:32 PM »
Roland,

minischeme/msinit had been designed to comply with R4RS and was written long before R5RS emerged. The later R5RS introduced a macro language that enabled much more elaborate macros to be designed and included as standard library extensions.

The Lisp/Scheme community turned out to be much wiser and farseeing than BASIC in sponsoring regular language developer conferences to work out guidelines and recommendations along which the community would like to see their languages developed. Conversely, the BASIC community proved itself a stagnant swamp in this regard floundering in the dialects that had very little to offer beyond troglodyte Dartmouth.

Aurel

  • Guest
Re: Updating OxyScheme
« Reply #59 on: December 08, 2019, 04:59:05 AM »
sponsoring regular language developer
sponsoring  with what ?
..and where are all that friendly lisp/scheme/..and dialects community
i really doubt that people who visit this forum take care about lisp/scheme
but that is just me ..the stupid hobby basic-only so called programmer ..he he