fix: a string seqs as characters, not one-character strings
(map int "IHDR") is how a PNG encoder writes a chunk type; it needs chars. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
af5c846 parent: 59d1739 modified
examples/hostfns.clj +3 -0 | @@ -29,3 +29,6 @@ | ||
| 29 | 29 | (let [v (volatile! 1)] (vreset! v 9) (println @v (vswap! v + 1))) ; 9 10 |
| 30 | 30 | (println (boolean nil) (instance? (class (int-array 0)) (int-array 2))) |
| 31 | 31 | (println (try (throw (ex-info "boom" {})) (catch Exception e (ex-message e)))) |
| 32 | + | |
| 33 | +;; a string is a sequence of characters | |
| 34 | +(println (map int "IHDR") (first "xy") (apply str (reverse "abc"))) | |
| @@ -29,3 +29,6 @@ | |||
| 29 | (let [v (volatile! 1)] (vreset! v 9) (println @v (vswap! v + 1))) ; 9 10 | 29 | (let [v (volatile! 1)] (vreset! v 9) (println @v (vswap! v + 1))) ; 9 10 |
| 30 | (println (boolean nil) (instance? (class (int-array 0)) (int-array 2))) | 30 | (println (boolean nil) (instance? (class (int-array 0)) (int-array 2))) |
| 31 | (println (try (throw (ex-info "boom" {})) (catch Exception e (ex-message e)))) | 31 | (println (try (throw (ex-info "boom" {})) (catch Exception e (ex-message e)))) |
| 32 | + | ||
| 33 | +;; a string is a sequence of characters | ||
| 34 | +(println (map int "IHDR") (first "xy") (apply str (reverse "abc"))) | ||
modified
src/runtime.nim +1 -1 | @@ -689,7 +689,7 @@ proc toSeq*(v: Value): seq[Value] = | ||
| 689 | 689 | of kList, kVector, kSet, kCons, kChunk, kLazy: v.items |
| 690 | 690 | of kStr: |
| 691 | 691 | var r: seq[Value] = @[] |
| 692 | - for c in v.s: r.add mkStr($c) | |
| 692 | + for c in v.s: r.add mkChar(int64(ord(c))) | |
| 693 | 693 | r |
| 694 | 694 | of kMap: |
| 695 | 695 | var r: seq[Value] = @[] |
| @@ -689,7 +689,7 @@ proc toSeq*(v: Value): seq[Value] = | |||
| 689 | of kList, kVector, kSet, kCons, kChunk, kLazy: v.items | 689 | of kList, kVector, kSet, kCons, kChunk, kLazy: v.items |
| 690 | of kStr: | 690 | of kStr: |
| 691 | var r: seq[Value] = @[] | 691 | var r: seq[Value] = @[] |
| 692 | - for c in v.s: r.add mkStr($c) | 692 | + for c in v.s: r.add mkChar(int64(ord(c))) |
| 693 | r | 693 | r |
| 694 | of kMap: | 694 | of kMap: |
| 695 | var r: seq[Value] = @[] | 695 | var r: seq[Value] = @[] |
modified
tests/hostfns.expected +1 -0 | @@ -14,3 +14,4 @@ true true true true 2 | ||
| 14 | 14 | 9 10 |
| 15 | 15 | false true |
| 16 | 16 | boom |
| 17 | +(73 72 68 82) x cba | |
| @@ -14,3 +14,4 @@ true true true true 2 | |||
| 14 | 9 10 | 14 | 9 10 |
| 15 | false true | 15 | false true |
| 16 | boom | 16 | boom |
| 17 | +(73 72 68 82) x cba | ||