-
-
Save y2q-actionman/8c0d0b7fbdfaae8a0ff979ea4b4501ba to your computer and use it in GitHub Desktop.
with-c-syntax backquote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CL-USER> '#{ *tmp*[1] * *tmp*[2]; }# | |
(WITH-C-SYNTAX.CORE:WITH-C-SYNTAX (:KEYWORD-CASE :UPCASE) | |
*TMP* | |
[ | |
1 | |
] | |
* | |
*TMP* | |
[ | |
2 | |
] | |
|;|) | |
CL-USER> (macroexpand *) | |
(LET* () | |
(DECLARE (DYNAMIC-EXTENT) (SPECIAL)) | |
(LABELS () | |
(WITH-C-SYNTAX.CORE::WITH-DYNAMIC-BOUND-SYMBOLS NIL | |
(BLOCK NIL | |
(TAGBODY | |
(RETURN (* (WITH-C-SYNTAX.CORE::LISP-SUBSCRIPT *TMP* 1) | |
(WITH-C-SYNTAX.CORE::LISP-SUBSCRIPT *TMP* | |
2)))))))) | |
T | |
CL-USER> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CL-USER> (named-readtables:in-readtable with-c-syntax:with-c-syntax-readtable) | |
(("COMMON-LISP-USER" | |
. #<readtable named WITH-C-SYNTAX.CORE.WITH-C-SYNTAX-READTABLE @ | |
#x10032e4f92>)) | |
CL-USER> #{ format (t, "Hello World!"); }# | |
Hello World! | |
NIL | |
CL-USER> #{ `(); }# | |
NIL | |
CL-USER> #{ `(+ 1 2); }# | |
3 | |
CL-USER> #{ `(loop for i from 1 to 100 sum i); }# | |
5050 | |
CL-USER> #{ `(loop for i from 1 to 100 sum i) - `(loop for i from 1 to 50 sum i); }# | |
3775 | |
CL-USER> (defvar *tmp* '(1 2 3 4 5)) | |
*TMP* | |
CL-USER> #{ *tmp*[1][2]; }# | |
; Evaluation aborted on #<WITH-C-SYNTAX.CORE::RUNTIME-ERROR @ #x10039dfa82>. | |
CL-USER> (defparameter *tmp* (vector 1 2 3 4 5)) | |
Warning: *TMP* is defined more than once as `variable' in file NIL. | |
*TMP* | |
CL-USER> #{ *tmp*[1][2]; }# | |
; Evaluation aborted on #<SIMPLE-ERROR @ #x1003aa0cf2>. | |
CL-USER> #{ *tmp*[1]; }# | |
2 | |
CL-USER> #{ *tmp*[1] * *tmp*[2]; }# | |
6 | |
CL-USER> #{ *tmp*[1] * *tmp*[2]; }# | |
6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* #{ -> ` -> #{ をネストできるように | |
* flet や handler-case や with-open-file で遊ぶと nest の例できそう | |
* struct 対応 | |
* vacietis に触れる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; なんか手元にあったコード | |
(ql:quickload :with-c-syntax) | |
(with-c-syntax:use-reader) | |
(defun w-c-s-duff-device (to-seq from-seq cnt) | |
(with-c-syntax:with-c-syntax () | |
#{ | |
int * to = & to-seq; | |
int * from = & from-seq; | |
int n = (cnt + 7) / 8; | |
n = floor(n); /* Lisp's CL:/ produces rational */ | |
switch (cnt % 8) { | |
case 0 : do { * to ++ = * from ++; | |
case 7 : * to ++ = * from ++; | |
case 6 : * to ++ = * from ++; | |
case 5 : * to ++ = * from ++; | |
case 4 : * to ++ = * from ++; | |
case 3 : * to ++ = * from ++; | |
case 2 : * to ++ = * from ++; | |
case 1 : * to ++ = * from ++; | |
} while (-- n > 0); | |
} | |
}#) | |
to-seq) | |
(with-c-syntax:with-c-syntax () | |
#{ | |
struct hoge { | |
int i, j; | |
}; | |
}#) | |
(with-c-syntax:with-c-syntax () | |
#{ | |
struct hoge make-struct () { | |
struct hoge ret; | |
ret . i = 0; | |
ret . j = 1; | |
return ret; | |
} | |
void fill-struct (struct hoge * s) { | |
s -> i = 999; | |
s -> j = 999; | |
} | |
}#) | |
(with-c-syntax:with-c-syntax () | |
#{ | |
struct hoge h; | |
h = make-struct(); | |
fill-struct(& h); | |
format(t, "~&~A ~A~%", h . i , h . j); | |
return h; | |
}#) | |
(defun hoge () | |
(let ((arr (make-array 100))) | |
(dotimes (i 100) | |
#3{ arr[i] = ++i; }# | |
) | |
arr)) | |
(defun typedef () | |
(with-c-syntax:with-c-syntax () | |
#{ | |
typedef int int_t \; | |
int_t x = 1 \; | |
return x \; | |
}# | |
)) | |
#| | |
CL-USER> #{ | |
int x = `(list 1 2 3); | |
return x; | |
}# | |
(1 2 3) | |
CL-USER> #{ | |
int x = list (1, 2, 3); | |
return x; | |
}# | |
(1 2 3) | |
CL-USER> #{ | |
auto x = list (1, 2, 3); | |
return x; | |
}# | |
(1 2 3) | |
CL-USER> | |
|# | |
(with-c-syntax:unuse-reader) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment