Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more code examples to lisp #542

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions dsk/tmp/lisp/fetch.lsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# HTTP/0.9 Proxy (https://github.com/vinc/fetch)

(load "/lib/lisp/core.lsp")

(var proxy-host "10.0.2.2")
(var proxy-port 8888)

(var stdout 1)
(var socket (socket.connect "tcp" proxy-host proxy-port))
(file.write socket (str->bin (str "GET " (nth args 0) "\n")))
(var open true)
(while open (do
(var buf (file.read socket 2048))
(file.write stdout buf)
(set open (not (nil? buf)))))
13 changes: 13 additions & 0 deletions dsk/tmp/lisp/ntp.lsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(load "/lib/lisp/core.lsp")

(var addr (nth args 0)) # Run `host pool.ntp.org` to get an address
(var port 123)
(var socket (socket.connect "udp" addr port))

(var req (map (fun (i) (if (eq? i 0) 0x33 0)) (range 0 48)))
(file.write socket req)
(var res (file.read socket 48))

(var buf (slice res 40 4))
(var time (- (bin->num (concat '(0 0 0 0) buf) "int") 2208988800))
(print time)
2 changes: 2 additions & 0 deletions src/usr/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ pub fn copy_files(verbose: bool) {
create_dir("/tmp/lisp", verbose);
copy_file("/tmp/lisp/colors.lsp", include_bytes!("../../dsk/tmp/lisp/colors.lsp"), verbose);
copy_file("/tmp/lisp/factorial.lsp", include_bytes!("../../dsk/tmp/lisp/factorial.lsp"), verbose);
//copy_file("/tmp/lisp/fetch.lsp", include_bytes!("../../dsk/tmp/lisp/ntp.lsp"), verbose);
copy_file("/tmp/lisp/fibonacci.lsp", include_bytes!("../../dsk/tmp/lisp/fibonacci.lsp"), verbose);
copy_file("/tmp/lisp/geotime.lsp", include_bytes!("../../dsk/tmp/lisp/geotime.lsp"), verbose);
//copy_file("/tmp/lisp/ntp.lsp", include_bytes!("../../dsk/tmp/lisp/ntp.lsp"), verbose);
copy_file("/tmp/lisp/pi.lsp", include_bytes!("../../dsk/tmp/lisp/pi.lsp"), verbose);
copy_file("/tmp/lisp/sum.lsp", include_bytes!("../../dsk/tmp/lisp/sum.lsp"), verbose);

Expand Down
Loading