Skip to content

Commit

Permalink
hdplisp (#18): added several examples from other lisps (and non-lisps…
Browse files Browse the repository at this point in the history
…, like Ada and Haskell)
  • Loading branch information
fititnt committed Apr 10, 2021
1 parent 1cb8de3 commit 2f60059
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hxlm-js/bootstrapper/lisp/datatype.mjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
// TODO: this is an draft
// https://en.wiktionary.org/wiki/dictionarium#Latin
// https://en.wiktionary.org/wiki/dictionarium#Latin
// https://clojure.org/reference/data_structures
// https://docs.racket-lang.org/guide/datatypes.html
// Ada:
// Strong data type
// - https://learn.adacore.com/courses/intro-to-ada/chapters/strongly_typed_language.html
2 changes: 2 additions & 0 deletions tests/hdplisp/other-inspirations/ada-extra.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- TODO: maybe add examples of Ada with contracts
-- @see https://learn.adacore.com/
11 changes: 11 additions & 0 deletions tests/hdplisp/other-inspirations/haskell-math.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{-
https://tryhaskell.org/
Command line interpreter: ghci
ghci tests/hdplisp/other-inspirations/haskell-math.hs
runhaskell tests/hdplisp/other-inspirations/haskell-math.hs
-}

main = putStrLn "Hello world!"

values = [1..10]
69 changes: 69 additions & 0 deletions tests/hdplisp/other-lisps/clojure-extra.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
;; https://en.wikipedia.org/wiki/Clojure
;; Interpreter:
;; clojure


(println "Hello world!")

;; define a var
(def a 42)
;; => #'user/a

;; call a function named `+`
(+ a 8)
;; => 50

;; call a function named `even?`
(even? a)
;; => true

;; define a function that returns the remainder of `n` when divided by 10
(defn foo [n] (rem n 10))
;; => #'user/foo

;; call the function
(foo a)
;; => 2

;; print the docstring of `rem`
(doc rem)
;; =>
;; -------------------------
;; clojure.core/rem
;; ([num div])
;; remainder of dividing numerator by denominator.
;;

;; print the source of `rem`
(source rem)
;; =>
;; (defn rem
;; "remainder of dividing numerator by denominator."
;; {:added "1.0"
;; :static true
;; :inline (fn [x y] `(. clojure.lang.Numbers (remainder ~x ~y)))}
;; [num div]
;; (. clojure.lang.Numbers (remainder num div)))


;; define a function (with a docstring) that
;; returns the remainder of `n` when divided by 10
(defn foo2 "returns `(rem n 10)`" [n] (rem n 10))
;; #'user/foo2

(doc foo2)
;; -------------------------
;; user/foo2
;; ([n])
;; returns `(rem n 10)`
;; nil



;; More structured hello world

;; A typical entry point of a Clojure program:
;; `-main` function
(defn -main ; name
[& args] ; (variable) parameters
(println "Hello, World!")) ; body
11 changes: 11 additions & 0 deletions tests/hdplisp/other-lisps/clojure-math.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; https://en.wikipedia.org/wiki/Clojure


(+ 1 2 3 4 5 6 7 8 9)
;; 45

(- 1 2 3 4 5 6 7 8 9)
;; -43

(quote (+ 1 1))
;; (+ 1 1)
6 changes: 6 additions & 0 deletions tests/hdplisp/other-lisps/common-lisp-extra.cl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
;; https://rosettacode.org/wiki/Hello_world/Text#Common_Lisp


;; (format t "Hello world!~%")

(print "Hello world!")
3 changes: 3 additions & 0 deletions tests/hdplisp/other-lisps/racket-extra.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#lang racket

(printf "Hello world!\n")
11 changes: 11 additions & 0 deletions tests/hdplisp/other-lisps/racket-math.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#lang racket


(+ 1 2 3 4 5 6 7 8 9)
;; 45

(- 1 2 3 4 5 6 7 8 9)
;; -43

(quote (+ 1 1))
;; '(+ 1 1)
10 changes: 10 additions & 0 deletions tests/hdplisp/other-lisps/scheme-extra.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; https://rosettacode.org/wiki/Hello_world/Text#Scheme
;; https://en.wikipedia.org/wiki/Scheme_(programming_language)

;; R5RS
(display "Hello world!")

;; R7RS
(import (scheme base)
(scheme write))
(display "Hello world!")

0 comments on commit 2f60059

Please sign in to comment.