Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
NalaGinrut / recv.scm
Created August 12, 2013 07:34
recv.scm of termite port to GNU Guile. NOTE: this may not be the best port, but it seems logical for the expanding of hygienic macro.
;; All hail the RECV form
(define-syntax-rule (recv . clauses)
(let ((msg (gensym "msg")) ;; the current mailbox message
(loop (gensym "loop"))) ;; the mailbox seeking loop
;; check the last clause to see if it's a timeout
(let ((sesualc (reverse clauses)))
(if (and (pair? (car sesualc))
(eq? (caar sesualc) 'after))
@NalaGinrut
NalaGinrut / time_test.c
Created August 12, 2013 09:39
times function tested under GNU/Hurd, it always returns all zero in tms struct. PS: it's OK under GNU/Linux
#include <sys/times.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct tms buf;
if (times(&buf) < 0)
exit(115);
@NalaGinrut
NalaGinrut / naive-aot.scm
Last active December 21, 2015 04:19
very naive AOT half-baked compiler for unfinished Guile brand new Register VM. It's only a toy since the RTL branch is still is very experimental.
(use-modules (ice-9 match))
(define test
'((begin-program self1180 ())
(label kentry1181)
(begin-kw-arity (x y) () #f () #f 3 #f)
(label kargs1182)
(add 1 1 2)
(label ktail1189)
(return 1)
String sStart = "1111111110000000000";
String sStop = "0";
int data_to_spoof[64];
int coil_pin = 9; // we use 9th pin
int a,b,c,d;
unsigned long id;
char hex_code[8];
void setup()
{
@NalaGinrut
NalaGinrut / frame.py
Created August 24, 2013 15:17
encode a frame for arduino TTS
def str_to_playframe(s0):
ss = s0.decode("utf-8")
l = "%c%c" % ((len(ss)&0xff00)>>8, len(ss)&0xff)
s = ss.encode("GB2312")
op = "\x01\x00"
return "\xfd" + l + op + s
@NalaGinrut
NalaGinrut / string-template.scm
Last active December 21, 2015 17:08
a Python3 style string-template for Scheme
(define *stpl-SRE* '(or (=> dollar "$$")
(: "${" (=> name (+ (~ #\}))) "}")))
(define (make-string-template str . opts)
(define ll '())
(define lv '())
(define template
(irregex-replace/all
;;"(\\$\\{([^$])+\\})"
*stpl-SRE* str
(lambda (m)
(define-module (test-suite web-client)
#:use-module (web client)
#:use-module (web request)
#:use-module (web response)
#:use-module (ice-9 iconv)
#:use-module (ice-9 binary-ports)
#:use-module (test-suite lib))
(define get-request-headers:www.gnu.org/software/guile/
diff --git a/test-suite/tests/web-client.test b/test-suite/tests/web-client.test
index 3133b73..6038398 100644
--- a/test-suite/tests/web-client.test
+++ b/test-suite/tests/web-client.test
@@ -299,13 +299,28 @@ Content-Language: en
")
;; Unfortunately, POST to http://www.gnu.org/software/guile/ succeeds!
+(define post-request-headers-null:www.apache.org/
+ "POST / HTTP/1.1
@NalaGinrut
NalaGinrut / gg.scm
Last active December 23, 2015 23:29
求from到to之间所有勾股数
(use-modules (srfi srfi-1) (ice-9 control))
(define (either . args) (shift k (for-each k args)))
(define (sq x) (* x x))
(define (choice from to)
(reset (let ((ll (iota to from)))
(let ((x (apply either ll))(y (apply either ll))(z (apply either ll)))
(if (= (sq z) (+ (sq x) (sq y)))
(format #t "~a^2 + ~a^2 = ~a^2~%" x y z))))))
@NalaGinrut
NalaGinrut / print-doc.scm
Created October 10, 2013 08:34
print all doc-string in current-module in Guile
(for-each (lambda (s)
(let ((p (module-ref (current-module) s)))
(if (procedure? p)
(format #t "[~a]~%~@[~a~%~]" p (procedure-documentation p)))))
(apropos-internal ".*"))