Skip to content

Commit

Permalink
Add default initial values for all numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Aug 22, 2023
1 parent c3f09b6 commit d6dc0e4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
32 changes: 32 additions & 0 deletions code/extrinsic/test/test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,35 @@
(loop for i from 1 to 5 and
j = i then (+ j i)
collect j))))

(define-test loop-wth-init.01
(is equal
(khazern-extrinsic:loop with x t
finally (return x)
until t
return 1)
nil))

(define-test loop-wth-init.02
(is equal
(khazern-extrinsic:loop with x fixnum
finally (return x)
until t
return 1)
0))

(define-test loop-wth-init.03
(is equal
(khazern-extrinsic:loop with x float
finally (return x)
until t
return 1.0)
0.0))

(define-test loop-wth-init.04
(is equal
(khazern-extrinsic:loop with x of-type (unsigned-byte 8)
finally (return x)
until t
return 1)
0))
7 changes: 3 additions & 4 deletions code/with-clause.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@

(defmethod wrap-subclause ((subclause with-subclause-no-form) inner-form)
`(let ,(map-variable-types (lambda (var type)
`(,var ,(case type
(fixnum 0)
(float 0.0)
(t nil))))
`(,var ,(if (subtypep type 'number)
(coerce 0 type)
nil)))
(var-spec subclause) (type-spec subclause))
,inner-form))

Expand Down

0 comments on commit d6dc0e4

Please sign in to comment.