Skip to content

Commit dfbe6d9

Browse files
committed
Small tweak to utils.rkt
1 parent 9b64842 commit dfbe6d9

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

langs/outlaw/utils.rkt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010
(define (symbol->data-label s)
1111
(to-label "data_" s))
1212

13+
;; Char -> String
14+
(define (char-encode c)
15+
(if (or (char<=? #\a c #\z)
16+
(char<=? #\A c #\Z)
17+
(char<=? #\0 c #\9)
18+
(memq c '(#\_ #;#\$ #\# #\@ #\~ #\. #\?)))
19+
(make-string 1 c)
20+
(string-append "$" (number->string (char->integer c) 16))))
21+
1322
(define (to-label prefix s)
1423
(string->symbol
15-
(string-append
16-
prefix
17-
(apply string-append
18-
(map (λ (c)
19-
(if (or (char<=? #\a c #\z)
20-
(char<=? #\A c #\Z)
21-
(char<=? #\0 c #\9)
22-
(memq c '(#\_ #;#\$ #\# #\@ #\~ #\. #\?)))
23-
(make-string 1 c)
24-
(string-append "$" (number->string (char->integer c) 16))))
25-
(string->list (symbol->string s)))))))
24+
(string-append prefix
25+
(apply string-append
26+
(map char-encode
27+
(string->list (symbol->string s)))))))
2628

2729
;; Id CEnv -> [Maybe Integer]
2830
(define (lookup x cenv)

0 commit comments

Comments
 (0)