Skip to content

Commit

Permalink
Version 7.9 added while
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-mattei committed Mar 30, 2024
1 parent 1100b69 commit 8b0a470
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
**
<v v>
⇜ ⇝
if repeat do when unless
if repeat do when unless while

%
<< >>
Expand Down
33 changes: 32 additions & 1 deletion src/while-do.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

;; but 'do in Scheme has a painful syntax

;; syntax defined in this file are inspired from Pascal language
;; syntax defined in this file are inspired from Pascal language, C , Java,Javascript

;; scheme@(guile-user)> (use-modules (Scheme+))
;; scheme@(guile-user)> (define i 0)
Expand Down Expand Up @@ -128,6 +128,13 @@
;; 27
;; 81
;; 243

;; > (do (define j i) (display "toto") (newline) (set! i (+ i 1)) while (< j 4))
;; toto
;; toto
;; toto
;; toto
;; toto
(define-syntax do
(syntax-rules (while)

Expand All @@ -141,4 +148,28 @@



;; > (define x 0)
;; > (while (< x 10)
;; (define y x)
;; (display y)
;; (newline)
;; (set! x (+ x 1)))
;; 0
;; 1
;; 2
;; 3
;; 4
;; 5
;; 6
;; 7
;; 8
;; 9
;; >
(define-syntax-rule (while condition body ...)
(let loop ()
(when condition
body ...
(loop))))



0 comments on commit 8b0a470

Please sign in to comment.