-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.scm
38 lines (34 loc) · 1.45 KB
/
example.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
;;; n: a number, used as a size
;;; list_: a list of structs
(define (example n list_)
;;; TODO In a real life scenario, you will describe here what you want the
;;; end user to do with this generated code
(newline))
(define (parse-int-list str)
(if (string=? "" str) '()
(let loop ((l (string->list str)) (s 1) (i 0))
(cond
((null? l) (list (* i s)))
((char=? #\space (car l)) (cons (* i s) (loop (cdr l ) 1 0)))
((char=? #\- (car l)) (loop (cdr l) (* -1 s) i))
(else (loop (cdr l) s (+ (* i 10) (- (char->integer (car l)) 48))))))))
(define (make-list i f) (if (= 0 i) '() (cons (f) (make-list (- i 1) f))))
(define (make-assoc-list-oneline k b)
(let loop ((l (string->list (read-line))) (k k) (b b) (c '()))
(let ((conv (lambda () (if (eq? 'char (car b))
(car c)
((if (eq? 'int (car b)) values exact->inexact)
(string->number (list->string (reverse c))))))))
(cond
((null? l) (list (cons (car k) (conv))))
((char=? #\space (car l)) (cons (cons (car k) (conv))
(loop (cdr l) (cdr k) (cdr b) '())))
(else (loop (cdr l) k b (cons (car l) c)))))))
(let* ((n (string->number (read-line)))
(list_
(make-list
n
(lambda
()
(make-assoc-list-oneline '(integer character) '(int char))))))
(example n list_))