1
0
mirror of https://github.com/janet-lang/janet synced 2025-04-14 23:03:13 +00:00
Add chr macro.
This commit is contained in:
Calvin Rose 2020-03-10 22:46:18 -05:00
parent a3d4ecddba
commit 77343e02e9
3 changed files with 11 additions and 0 deletions

View File

@ -2,6 +2,7 @@
All notable changes to this project will be documented in this file.
## Unreleased
- Add `chr` macro.
- Allow `_` in the `match` macro to match anything without creating a binding
or doing unification.
- Add `:range-to` and `:down-to` verbs in the `loop` macro.

View File

@ -316,6 +316,13 @@
,payload
(propagate ,res ,fib)))))
(defmacro chr
"Convert a string of length 1 to its byte (ascii) value at compile time."
[c]
(unless (and (string? c) (= (length c) 1))
(error (string/format "expected string of length 1, got %v" c)))
(c 0))
(defmacro label
"Set a label point that is lexically scoped. Name should be a symbol
that will be bound to the label."

View File

@ -136,4 +136,7 @@
(assert (deep= @"cde" (buffer/blit @"" a -1 2 5)) "buffer/blit 4")
(assert (deep= @"de" (buffer/blit @"" a -1 3 5)) "buffer/blit 5")
# chr
(assert (= (chr "a") 97) "chr 1")
(end-suite)