-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hdplisp (#18): added several examples from other lisps (and non-lisps…
…, like Ada and Haskell)
- Loading branch information
Showing
9 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#lang racket | ||
|
||
(printf "Hello world!\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |