God writes in Lisp

Demo of importing a few libraries in kawa-scheme,

Code:
;; -*- coding:utf-8; mode:Scheme -*-

(module-name 'MyTest)
(module-compile-options main: #t)

;(require 'srfi-69) ;; Basic hash tables
;(require 'srfi-101) ;; Purely Functional Random-Access Pairs and Lists
(require 'srfi-1) ;;  List Library
(require 'srfi-2) ;;  AND-LET*: an AND with local bindings, a guarded LET* special form
(require 'srfi-8) ;;  receive: Binding to multiple values
(require 'srfi-10) ;; #, external form
(require 'srfi-13) ;; String Libraries
(require 'srfi-14) ;; Character-set Library
(require 'srfi-26) ;; Notation for Specializing Parameters without Currying
(require 'srfi-34) ;; Exception Handling for Programs
(require 'srfi-35) ;; Conditions
(require 'srfi-37) ;; args-fold: a program argument processor
(require 'srfi-41) ;; Streams
(require 'srfi-41-streams-derived);;
(require 'srfi-60) ;; Integers as Bits
(require 'srfi-64) ;; A Scheme API for test suites
(require 'srfi-95) ;; Sorting and Merging

;(require 'hash-table) ;;
(require 'list-lib) ;;
(require 'condition) ;;
(require 'conditions) ;;
(require 'testing);;

;(import kawa.lib.scheme.base)
(import kawa.lib.scheme.case-lambda)
(import kawa.lib.scheme.char)
(import kawa.lib.scheme.complex)
(import kawa.lib.scheme.cxr)
(import kawa.lib.scheme.eval)
(import kawa.lib.scheme.inexact)
(import kawa.lib.scheme.lazy)
(import kawa.lib.scheme.load)
(import kawa.lib.scheme.process-context)
(import kawa.lib.scheme.read)
(import kawa.lib.scheme.repl)
(import kawa.lib.scheme.time)
(import kawa.lib.scheme.write)
(import kawa.lib.scheme.r5rs)

;(import kawa.lib.rnrs.hashtables)
;(import kawa.lib.rnrs.lists)
(import kawa.lib.rnrs.arithmetic.bitwise)
(import kawa.lib.rnrs.programs)
(import kawa.lib.rnrs.sorting)
(import kawa.lib.rnrs.unicode)

;(import kawa.lib.kawa.base)
(import kawa.lib.kawa.arglist)
(import kawa.lib.kawa.expressions)
(import kawa.lib.kawa.hashtable)
(import kawa.lib.kawa.swing)
(import kawa.lib.kawa.regex)
(import kawa.lib.kawa.reflect)
(import kawa.lib.kawa.pprint)
(import kawa.lib.kawa.string-cursors)
(import kawa.lib.kawa.quaternions)

;(import gnu.kawa.slib.srfi69)
(import gnu.kawa.slib.srfi1)
(import gnu.kawa.slib.srfi2) 
(import gnu.kawa.slib.srfi13) 
(import gnu.kawa.slib.srfi14)
(import gnu.kawa.slib.srfi34)
(import gnu.kawa.slib.srfi37)
(import gnu.kawa.slib.srfi60)

(define (main)
    (display (iota 5 0 -0.5))
    (display "Hello"))
(main)

To run:

Code:
rm -vfR ./test.class ./quote
kawa --main -C ./Test.scm
kawa quote.MyTest
 
A demostration of modules in kawa-scheme:

MyTestA.scm
Code:
(module-name MyTestA)
(module-export printa)
(define (printa)
    (display "A"))

MyTestB.scm
Code:
(module-name MyTestB)
(module-export printb)
(define (printb)
    (display "B"))
MyTest.scm
Code:
(module-name MyTest)
(module-compile-options main: #t)
(define (printc)
    (display "c"))
(require 'srfi-1) ;;  List Library
(define (main)
    (import MyTestA)
    (printa)
    (MyTestB:printb)
    (printc))
(main)

To compile & run:
Code:
rm -vf ./*.class
kawa -Dkawa.import.path="." -C ./MyTestA.scm
kawa -Dkawa.import.path="." -C ./MyTestB.scm
kawa -Dkawa.import.path="." --main -C ./MyTest.scm
kawa MyTest
 
You want a Kawaii Schemer, here's one:
1697489188461.png

😈
 
Coalton is a very fascinating language to program in due to it's possible flexibility and possible sturdiness of compile-time-type-checking & static-typing,
Here the complete library,
&
A demo code,

Code:
(load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3) (space 0) (debug 3)))
(ql:quickload "serapeum")
(ql:quickload "coalton")

(defpackage package-main
    (:use
        #:cl 
        #:serapeum)
    (:local-nicknames 
        (#:n #:coalton))
    (:export main printstring)) ;defpackage

(defpackage package-coalton
    (:use 
        #:coalton-prelude
        #:coalton)
    (:local-nicknames 
        (#:l  #:cl)
        (#:nl #:coalton-library/list)
        (#:ns #:coalton-library/string)
        (#:nc #:coalton-library/cell)
                )
    (:export cmain));defpackage

;-----------------------------------------------------------------------
(in-package :package-coalton)
(coalton-toplevel

    (declare txtmod (cell String))
    (define txtmod (nc:new " Variable-text "))

    (define-type IntList (IntList (List Integer)))
    (declare alist IntList)
    (define alist (IntList(range 1 5)))
    (declare blist IntList)
    (define blist (IntList Nil))

    (declare joinstring(String -> String -> String))
    (define(joinstring x y)
        (ns:concat x y))

    (declare getstring(Unit -> String))
    (define (getstring)
        (ns:concat astring bstring))

    (declare astring String)
    (define astring " Hello ")
    (declare bstring String)
    (define bstring " World ")

    (declare printstring (String -> Unit))
    (define (printstring s)
        (Lisp Unit(s) (l:princ s) Unit))

    (declare printlist(IntList -> Unit))
    (define (printlist s)
        (Lisp Unit(s) (l:princ s) Unit))

    (declare cmain (Unit -> Unit))
    (define (cmain)
        (nc:write! txtmod " New Text ")
        (Lisp Unit() (package-main:printstring (nc:read txtmod)) Unit)
        (printlist alist)
        (printstring(getstring)) Unit)) ;toplevel

;-----------------------------------------------------------------------
(in-package :package-main)
( -> printstring (String) Boolean )
(defun printstring (s)
    (princ s) t)
( -> main () Integer)
(defun main()
    (package-coalton:cmain n:Unit) 0) ; main
(sb-ext:save-lisp-and-die "test.exe" :toplevel #'main :executable t)

To compile & run :
Code:
clear
rm *.exe
sbcl --script test.lisp
./test.exe
 
Interesting that I posted this because I thought the song was funny but it seems either nobody listened to it or nobody got the joke.
 
Something exotic, calling a dotnet function from IronScheme,

Code:
(import
    (rnrs)
    (ironscheme clr))
(define (write-ln fmt . args)
    (clr-static-call 
        System.Console WriteLine (clr-cast System.String fmt)
        (clr-cast System.Object[] (list->vector args))))
(write-ln "{0}" "Hello World from Ironscheme")

To compile & run,
Code:
dotnet IronScheme.ConsoleCore.dll -- ./test.ss

Source,
 
Are you learning one programming language a day, Alain?

Good for you. It widens one's perspective.

Different languages have a focus on different paradigms so I learn solving problems in different ways.
The Good : Ocaml , F# , Coalton ,typed-Racket.
OK : Scala-native , Kotlin , Chicken-Scheme ,
The Bad : Shen , V-lang , zig , pony , vala , janet , ceylon , clojure , groovy , abcl
 
Demo of calling a python-function & object-orientation using "hy-lisp",
Code:
(import math)
(print (math.cos math.pi)) ; calling python function

(defclass Triangle [object]
    (setv
        x 0
        y 0)
    (defn move-right [ self moveby ]
        (setv self.x (+ self.x moveby))))
(setv myt (Triangle ))
(myt.move-right 100)
(print myt.x)

To compile & run,
Code:
rm -vfR __* build
hyc ./test.hy
python3 ./__pycache__/test.cpython-39.pyc
cxfreeze ./__pycache__/test.cpython-39.pyc
./build/exe.freebsd-13.2-RELEASE-amd64-3.9/test.cpython-39
 
Demo of calling a java-function & object-orientation using "kawa-scheme",

Code:
(module-name MyTest)
(module-compile-options main: #t)

(define-simple-class 2d-vector ()
    (x type: double init-keyword: x:)
    (y type: double init-keyword: y:)
    ((*init* (x0 ::double) (y0 ::double))
        (set! x x0)
        (set! y y0))
    )

(define (main)
    (format #t "~a~%"
        (java.lang.Math:sqrt 9.0)) ; Calling java function
        
    (define v :: 2d-vector (2d-vector 1 2)) ; construct object
    (format #t "x: ~a~%" v:x))
(main)

To compile & run,
Code:
rm -vf ./*.class
kawa -Dkawa.import.path="." --main -C ./MyTest.scm
kawa MyTest
 
For sake of completeness, if you don't need a GUI or compile-time-type-checking then "gerbil-scheme" is a good choice.

Hello world in Gerbil-scheme:

1) Make a directory named example
2)Put in that directory the following two files:

gerbil.pkg
Code:
(package: example)

hello.ss
Code:
(export main)
(def (main . args)
  (displayln "hello, world"))

3)Run the script in order to compile to executable binary , and run,
Code:
export CC=gcc
export GERBIL_GCC=/usr/local/bin/gcc12
rm hello*
gxc -v -g -exe -o hello example/hello.ss
./hello
 
It's more easy to make yourself think in terms of a Turing machine if you write in Haskell.
Racket is more "impure". In Haskell it is easier.

Racket is largely implemented with Chez Scheme that I mentioned earlier.

Some Typed Racket features provide flexibility that Haskell cannot express, while keeping everything safe. For example, Typed Racket supports variable arity functions (like Racket's `+', `list', `map', etc.), dynamic type checks, optional and keyword arguments, etc.

Haskell takes the attitude that the type system is a fundamental part of the program design, and typed Racket takes the attitude that the program comes first, and the type system's job is to check that nothing is going to go wrong.

Of course, Haskell also provides type system features that Typed Racket does not, such as type classes or type-level programming.

Haskell is a mature, very old compiler. Typed Racket is an evolving, younger language.
I wonder if Typed Racket is going to be able to perform similarly as Haskell. Seems to me that Haskell can be much faster in some situations:

Racket 105.218 ± 0.312 sec
optimized Haskell 3.517 ± 0.009 sec

Haskell beats C

Benchmarks show that these Haskell programs can perform competitively with hand-written C.
Speed is not everything. In fact with my 12-core CPU. Speed is nothing.
Sometimes it's more the ability/flexibility to put an idea in your head into code.
Haskell is rigid. Maybe too rigid.
 
Speed is not everything. In fact with my 12-core CPU. Speed is nothing.
Sometimes is more the abilitu/flexibility to put an idea in your head into code.
Haskell is rigid. Maybe too rigid.

Common Lisp is a "speed optional" language that compiles down to assembly code without type checks or type tags and direct access to struct members (no pointers). That is why ITA software could use it for what is now Google Flights' search engine.
 
Common Lisp is a "speed optional" language that compiles down to assembly code without type checks or type tags and direct access to struct members (no pointers). That is why ITA software could use it for what is now Google Flights' search engine.
Now I know why there's so few fights to IPC (on Easter Island) 😈
 
Common Lisp is a "speed optional" language ...
That's one way to put it (scnr). But it is still right. I hate it when the language obscures the elegant solutions so you make suboptimal ones.
A good example should be the 8 queens problem where one assembler guy checked if a queen was at n*45 degrees. Needless to say simply checking dx/dy is faster, and he could not figure out how he was beaten by a basic program (C64 times).

But 32000 different fares per flight? What was going on? That is more than 100 per seat, is that fine tuning for "customer uses iPhone? y/n, drives a XYZ, ...."?
 
Back
Top