 tscoreμ˴ؤ

 Ĥδ֤ˤ꤬ä͡ġġ
äʤΤǡCellTypeƤθľ򤷤Ƥ

ϰʲ̤ꡣ
    enum CellType
    {
      FREE_CELL = 0,
      NUMBER_CELL = 1,
      CHARACTER_CELL = 2,
      SYMBOL_CELL = 3,
      FOREIGN_OBJECT_CELL = 4,
      PAIR_CELL = 5,
      STRING_CELL = 6,
      PROC_CELL = 7,
      CLOSURE_CELL = 8,
      CONTINUATION_CELL = 9,
      FOREIGN_FUNCTION_CELL = 10,
      PORT_CELL = 11,
      VECTOR_CELL = 12,
      PROMISE_CELL = 13,
      ENVIRONMENT_TEMPLATE_CELL = 14,
      ENVIRONMENT_INSTANCE_CELL = 15,
      BINDING_CELL = 16,
      REGEXP_CELL = 17,
      SUBSTRING_CELL = 18,
      PRIMITIVE_SYNTAX_CELL = 19,
      MACRO_SYNTAX_CELL = 20		// reserved
    };

FREE_CELL = 0;
ϳɤ

ATOM_FLAGѻߤΤǡATOMɤʬषƤߤ롣

ATOM: Cell *äƤʤvectorΤ褦˴̰Τ
      FREE_CELL = 0;
      NUMBER_CELL = 1,
      CHARACTER_CELL = 2,
      FOREIGN_OBJECT_CELL = 4,
      STRING_CELL = 6,
      PROC_CELL = 7,
      CONTINUATION_CELL = 9,
      FOREIGN_FUNCTION_CELL = 10,
      PORT_CELL = 11,
      VECTOR_CELL = 12,


ATOM: Cell *äƤ
      SYMBOL_CELL = 3,
      PAIR_CELL = 5,
      CLOSURE_CELL = 8,
      PROMISE_CELL = 13,
      ENVIRONMENT_TEMPLATE_CELL = 14,
      ENVIRONMENT_INSTANCE_CELL = 15,
      BINDING_CELL = 16,
      REGEXP_CELL = 17,
      SUBSTRING_CELL = 18,
      PRIMITIVE_SYNTAX_CELL = 19,
      MACRO_SYNTAX_CELL = 20		// reserved

ʤ󤫡ɤˤ褽ȾʬĤ̤줿衣

 ꥷƥ
ߤΤȤ̤young space + old spaceGenerational GCƤ
롣minor GC1ĤäCell2ܤminor GCold spacetenure
롣major GCTinySchemeͳMark&Sweep GCǡ¿ʬޤ®
ǤμŪˤʤ

old spaceyoung spaceȤȤcard_mark[]ͤ뤿write
barrierȤäƤ롣


 Cellnative(C++)ɽ
CellͤSchemeˤѤC++1ĤunionCellScheme
ɽGCΤʤɤѤղŪʾǼ뤿C++longͣ
ĤʤäƤꡢߣĤCell礭ϡ̤ΥƥǤϥ
󥿤󥰤ͣʬȤʤäƤ롣餯unionΥƤ
ΤFFIΤǤǡϥݥ󥿣ĤǼƤ롣FFI
APIѹСunionΥ(consμɽƱͤ)ݥ
ʬ˽̤뤳ȤϲǽҤ褦˳Cellˤunion˲ä
longͤ򣱤ĳǼƤ뤿ᡢ̤᤿ȤƤCellΤȤƤϥݥ
󥰣ʬ롣㤨IA32ǤdoubleΥ饤Ȥαƶʤɤ
θȡեåȥץȤ︺ǤȤϤäƤ⡢̵
ƣɤˤ٤ΤΤǤϤʤ

C++virtualؿʤɻȤСŪˤ¿Ǥʬ⤢뤬VM
ǤScheme򸫤ƤΤǼ¼Ūdynamic dispatchβͤϾʤ
static dispatchΤ¤C++ѥǤ᥽åɤinlining
Ǥ롣virtualؿϻȤʤˤꡢCellvtblݥ󥿰
ʬʤȤåȤԤƤ롣


 regexpϢ

 ץå
(regexp? ֥)
	 ֥Ȥɽ֥Ȥʤ#tʳʤ#f
	 ֤롣


 ƥ뵭
#/ɽ/
#/ɽ/i  case insensitive

 ʸ󤫤Ѵ
(string->regexp "ɽ")
	ɽ֥Ȥ֤

ʾ塢gaucheΥѥꡣ


(regexp-match-positions ɽ֥ "ʸ")
	ɽʸ˥ޥå̤ͽˤĤ
	substring( . λ)Τ褦consΥꥹȤ֤
	ޥåʤ#f֤

(regexp-match ɽ֥ "ʸ")
	ɽʸ˥ޥå̤ͽˤĤ
	substringΥꥹȤ֤ޥåʤ#f֤

(regexp-split ɽ֥ "ʸ")
	ɽ˥ޥåsubstringǥߥȤʸڤꡢ
	ڤ줿substringΥꥹȤ֤

(regexp-replace ɽ֥ "ʸ" "ִʸ")
	ʸκǽɽ˥ޥåʬִʸ֤
	ʸ֤ޥåʤϸʸ󤽤ΤΤ֤

(regexp-replace* ɽ֥ "ʸ" "ִʸ")
	ʸκǽɽ˥ޥåƤʬִʸ
	ʸ֤ޥåʤϸʸ󤽤ΤΤ
	

(regexp-quote "ʸ")
	Ϳ줿ʸΤ˥ޥåɽ֤ʤʸ
	ɽΥ᥿ʸޤޤƤˤ'\'ǥ
	פʸ֤

ʾ塢pregexpΥѥꡣ


substring˥ԡƺΤϤ٤⤤Τǡimmutable string
substringʸΤͭ褦ˤΤˤϡ
CellפȤsubstringƳΤ褤
substringϸʸΤstring CellؤΥݥ󥿤
substringĹsubstringθʸˤƬΥեåȤ
substringƬؤΥݥ(const char *)Τ줫ȤĤǤˤ
ɽǤ롣ܤǤˤĤƤϡʸ갷׷θ
ȡեåȤݥ󥿤Ѥ٤GCμ˼ä
ʤǺѤޤ뤿ᡢʸбstring CellؤΥݥ󥿤
carˡsubstringĹcdrCellɽ¸˲äsubstring
ƬؤΥݥ󥿤򵭲ɤsubstringʸμΤʤΤǡ
finalizeCʸfree()ɬפϤʤޤsubstring Cellˤϸ
string CellؤΥݥ󥿤¸ߤ뤿ᡢsubstring Cellliveʸ¤긵
string Cell⼫ưŪliveȤʤ롣
Τ褦ѹsubstringimmutable stringˤʤ롣


 äʸ󤬹⤯Ĥʡġġ
μǤϡsubstringкȤ߹ȤϤŪʸ
nativeҡפݤ롣ϡߤˤʤästring CellФ
finalize()¹Ԥޤǡߤˤʤänativeҡפ˳ݤ줿Cʸ
󤬲ʤȤfinalize()Ƥ֥ߥ󥰤Ϥߤˤʤä
Cell˺ѤľȤʤäƤ뤿ᡢfinalize()Υߥ󥰤GC
⹹˸ȤȤˤʤ뤬켫ΤܼǤϤʤޤ
ʸǤϤʤΤǡVMκ꤫ͤľɬפ롣

ͤ櫓ǤϤʤ㤨СVMCPSΥХȥɥ󥿥ץ
ˤǥեȤǤCell򥹥å˳Ƥ褦ˤƤơ
Хȥɤμ¹Ԥκݤˡ¿ξǤ륹åؤ
continuationƤֻǡäʬΥå˳Ƥ줿Cell
finalize()Ȥˤͤ¸뤿
ϡץʥꥷɬפǤꡢ㤨ХХѿ
黲ȤCellؿ֤ͤΤ褦˸ߤΥå饨פ
Cell˴ؤƤϡ̾VMҡפ˳ƤȤäƤɬפˤʤ롣
CPSǤʤ̤Υ꥿ΥХȥɥ󥿥ץ꥿ǤƱ
褦ʤȤϤǤɤƵбʬǤCPS
ȤäƱȤҤĤ褦顢̤ʤ
ʤʤΤݤȤcall/ccμ¸ͤCPS
ڤäݤCPSǥå򴬤᤹finalize()ˤ
ޤȤƽǤʬCellפʤȤƼ갷륱
褦ͽ


 ¹ԷϤ¤褦ʡ

 ߤμįʤΥ
interactive_replREPLΥ顼ȯο񤤤롣
Ūˤϡ顼ȯ˼¹ԤOP_ERR1Ȥopcodeμ¹Իν
ʲΤ褦˰ۤʤäƤ롣

interactive_repl = falseξ:
    (callerǤeval_cycle()Ф)nil֤
interactive_repl = trueξ: return s_goto(OP_T0LVL)ȤʤäƤΤǡ
    (callerǤeval_cycle()Ф)t֤

η̡interactive_repl = falseξˤ椬󥿥ץ꥿鴰
ȴ롣interactive_repl = trueξˤtop level롣


󥿥ץ꥿LoopΤeval_cycleǤꡢ
Read/Eval/PrintϤ줾졢
OP_READ_INTERNAL
OP_T1LVL
OP_VALUEPRINT
ȤopcodeȥˤʤäƤ褦TinySchemeΥ󥿥ץ꥿ϰ
CPSμˤʤäƤơʾopcodeOP_T0LVLˤäơå
Ѥޤ롣

OP_READ_INTERNALinport(ߤinput port)Sɤ߹Ǥ
֤(value˳Ǽƥå᤹)ȤopcodeS̾
Scheme֥(Cell)ǤꡢsymbolatomꥹȤˤʤäƤϤ

OP_VALUEPRINTϸߤoutput portstdoutʾˤϷ̤Ϥvalue
֤Ȥopcode

OP_T1LVLvaluecode˳ǼOP_EVAL˥פ롣

OP_EVALcodeμˤʲνԤ
  code->is_symbol()trueξ硢codeɽ줿symbolФ븽ߤδ
ˤ뵭֤õ¸ߤʤunbound variable顼򵯤
¸ߤˤϡƤ֤

  code->is_pair()true(scheme٥Ǥpair?#fˤʤ뤬)ξ硢
CAR(code)->is_syntax()TRUEʤsyntaxбopcode
CDR(code)򿷤codeȤopcode¹Ԥ롣ʳξ硢OP_E0ARGS
argsnilcodecodeȤƼ¹ԤΤcontinuationȤCAR(code)
OP_EVAL롣

  ʳξˤcodeΤΤ֤


줿ϤʤΤTinySchemeͳȻפevalͿ
줿symbolsyntaxɤȤȽ(intern줿symbolCell
*)->is_syntax()ǹԤäƤơsyntaxбsymbolϽ
assign_syntax()ˤäбsymbolset_syntax()ƤȤ
ꤵƤ롣μ϶餯鷺ʹ®ˤϤäƤΤ
R5RShygienic macroˤбǤʤ®Ūʴ̵뤹ȡ
٤ưϡevalоݤΥꥹȤκüsymbol򸫤Ĥ顢evalĶ
ɽƥ֥ȤΥ֥Ȥsyntaxʤ餽syntax
ꥹȤλĤŬѡprocedureʤ餽procedureꥹȤλĤŬѡġĤ
ƤʤȤɬפ롣

ȤTinySchemeλäƤmacroλͤΤʤΤǴ˴˾
ơR5RSsyntax-rulesˤޥ򥵥ݡȤ褦ȻפäƤ롣

ƱTinySchemeͳǡenvironmentΰƩʤΤä˥
λѤμ餫٤ʤΤǥåλȤޤƴ˽
ͽꡣ餯Хȥɥ󥿥ץ꥿ˤʤ롣󥿥ץ꥿λͤ
ͤŬʥХȥɤꤷƥХȥɥѥ
ɤηвɬפʥХȥɤΥåȤޤ
󥿥ץ꥿λͤⲿȤʤƤͽ

ѥ񤤤ƤߤʬꤽʤȤϡScheme˸symbol
ɤ١б뵭֤Ǥ˥ѥʤΤȤ
Ȥ䡢CellΥդ뤳Ȥͭñescape
ϤɤͭѤȤäԤθenvironmentɤɽ
ΤԤθϡ줬ͭʤΤǤС󥿥ץ꥿ι¤
ǽ餫դ򥵥ݡȤ褦߷פ٤夫
⸫̤ɤ


 Хȥɡʲ
۵ϥåޥˤ롣
쥸ϡ

Cell *value;
	ǿeval̤򵭲

const char *pc;
        ߼¹ΥХȥɤؤΥݥ

const char *npc;
        ߤprocedureˤƼ˼¹ԤХȥɤؤΥݥ


lambdaϥХȥѥѤοۤʤprocedure XɾǤ
Ϥ㤨С(lambda (x) x)
0: ߤclosureѿxΤ˳ĥ
1: åѤޤ줿ѿx˥ԡ
2: ߤclosurexɾ
3: return
Ȥprocedure XХȥѥ˺롣¹Իˤϡ
ɾδĶȤ߹碌ΤȤơ#<closure>뤳Ȥˤʤ롣


㤨lambdaȥåץ٥
(define foo (lambda (x) x))
Τ褦˻ȤƤ硢
Хȥѥη
(define foo [:procedure X])
̣ХȥɤѴǤ
evalȥȥåץ٥foo[procedure X]bind롣Ĥʤ
ФʤʤΤϡ[procedure X]scheme鲿餫ΥȤƸ
륪֥ȤȤƼ硢GCαƶǥ֥Ȥε֤
ư롣ʤΤǡŬʥơ֥(GC롼)procedure֥Ȥ
ǼƤơ֥index IȤƻȤ褦ˤɬ
롣

ŤäġġSchemeä
(define counter (lambda ()
	          (let ((x 0))
	            (lambda () (set! x (+ x 1)) x))))
ߤʴؿǤ롣
> (define c1 (counter))
#<PROCEDURE>
> (c1)
=> 1
> (c1)
=> 2
> (define c2 (counter))
#<PROCEDURE>
> (c1)
=> 3
> (c2)
=> 1
> (c1)
=> 4

κ(lambda () (set! x (+ x 1)))ǻȤƤxϳ¦
(let ((x 0))
  (lambda () (set! x (+ x 1)) x))
bindƤ뤬ʬɾ
(lambda ()
  (let ((x 0))
    (lambda () (set! x (+ x 1)) x)))
#<PROCEDURE>μ̿Ⱥ(lambda () (set! x (+ x 1)) x)
ɾ#<PROCEDURE>μ̿ҴطˤʤʤĤޤꡢ
ʸ̮ǻѤƤx̾Υå˳ݤ뤳ȤϤǤʤ
ޤɤ

Ĥޤlambdaɾ#<PROCEDURE>ˤϡŪˡ
#<PROCEDURE>⤫黲ȤƤ볰¦ξ(bindingǤʤѿ
)ɬפ롣줬closure

ʤ顢ŪñʲϤɬפʬåȤ褦ʥץ
ѴǤ

(define counter (lambda ()
	          (let ((x 0))
	            (cons (lambda () (set! x (+ x 1)) x)
			  (lambda () (set! x (- x 1)) x)))))
ߤʤȤˤʤä顢ʡݤ

ɥåե졼ҡפ˼äƤΤֳڤҡפΥ
γƤϡGenerational GCˤǥ󥿥ץ꥿®ʤ
٤Ȱ²餳ˤǹԤ


 ̣Τˤ뤿Ѹ
#<PROCEDURE>
	lambdaɾ̡nativeȤ߹ߤδؿ桼
	FFI֥ȡˤƤScheme鸫ե
	ȥ饹֥ȡ#<PROCEDURE>ϡlambdaɾ
	(bindingsǤʤб뵭ޤ᤿)Ķȡ
	#<PROCEDURE>ǤΥbindingsбĶ󥯤
	äƤ롣#<PROCEDURE>Ȥcall줿˻Ȥӥ
	ѿΤεϡ#<PROCEDURE>callưŪ˺
	롣
TinySchemeǤȤ߹ߤΤĤ#<PROCEDURE>ɽ롣Scheme
񤫤줿procedure(lambdaevalȤǤ)ϡ#<CLOSURE>ɽ
롣ޤschemeߤ񤤤ϻ褦ʤΤ



#<ENVIRONMENT>
	symbolϤȤơбsyntaxѿε()
	뤿ɬפȤơ֥ɽ#<ENVIRONMENT>ҹ¤
	¦#<ENVIRONMENT>ˤĤƤbindingsǤʤб
	뵭ɬ¸ߤ뤳Ȥꤷɤ

	̾REPLѤƤ¤ꡢΤ褦#<ENVIRONMENT>Ϣɬ
	¸ߤ롣

#<ENVIRONMENT "(null-environment 5)">			immutable
  R5RSsyntax bindingsĴĶ
    #<ENVIRONMENT "(scheme-report-environment 5)"	immutable
      R5RSprocedureǼѿؤbindingsɲä줿Ķ

	#<ENVIRONMENT "(interaction-environment)">
	TSCoreȼɲäprocedureѿؤbindingsɲä줿Ķ
	桼ץɾη줿binding	δĶ˴ޤ
	뤳Ȥˤ롣ȥåץ٥롣
	null-environmentscheme-report-environment
        interaction-environmentؤϢפʤΤǤᡣ
	null-environmentscheme-report-environmentȤϤä
        ˤʤϤʤΤǡsingletonȤƥåϤ뤬׵ᤵ
	Ȥ˿褦ˤ

	̾REPLϤδĶͿ줿ɾ롣㤨С
	(define foo (lambda (x) x))
	ɾȡ
	#<ENVIRONMENT "(interaction-environment)">ѿε褬
	졢ѿfooȤsymbolbind롣ޤ
	(lambda (x) x)ɾ#<PROCEDURE>ѿͤȤƳ
	Ǽ롣#<PROCEDURE>ˤϰxΡbindingפ̵̾
	#<ENVIRONMENT>Ǽ졢#<ENVIRONMENT>ϳ¦δĶȤ
	#<ENVIRONMENT "(interaction-environment)">ؤΥ󥯤ġ

	#<PROCEDURE>θƤӽФϡ褽Τ褦ʼˤʤ롣
	(1) #<PROCEDURE>˳Ǽ줿#<ENVIRONMENT>Фѿε
	    äʴĶ#<ENVIRONMENT>롣
	(2) (1)ǺäĶ˰ͤǼ롣
	(3) #<PROCEDURE>ΥɤƤӽФ


environmentˤϣढ롣ɤenvironmentȰenvironment
ȤΤϤƤbindingenvironmentbind줿ѿε
ΰenvironment̤ƹͤɬפꤽ

CellΥڡˤϸ¤꤬Τǡѿεΰenvironment
parent environmentؤΥݥ󥿤Ѥˡб롢binding
environmentؤΥݥ󥿤Ǽ롣ޤbindingenvironment
˥ݥ󥿤Ǽparent environmentѿεΰ
environmentǤȤ򤷤Ƥ褤ġ̯

Ȥꤢbindingenvironmentenvironment templateΰ
environmentˤenvironment instance̾դ뤳Ȥˤ롣

ɬפ˱delegateʤꤹ뤳Ȥǡload/storeenvironment
instantiateƤenvironmentؤΥƩŪ˹Ԥ褦
롣

㤨environment instanceФlookup()Ԥä硢б
environment templatelookup()delegate롣bind_variable()
bind_syntax()ξƱ͡

environment templateФload/store׵᤬äˤϥ顼(
ץ꥿μߥʤΤabort()Ƥ褤)
Ʊͤenvironment instanceФinstantiate׵᤬ä⥨顼


environment templateμȤƤbindingγǼˡȤhashtable
ΤlistȤΤΣѰդ뤳Ȥˤ롽ˤΤѤ
ġġ
environment instanceϣǽʬѿεˤvector
ȤդɬפʤΤϡѿεбbinding˽ä
ĥǽ뤳ȡstoreˤϳĥԤ롣loadˤ
εۤϰϤؤΥunbound variable顼ʤΤǡ
ĥϹԤʤ

environmentinstantiateˤϡνȤơenvironment
templateݻƤvariable bindingο + ʣCellʬɽ4
ʬˤѤ롣variable bindingοϡhashtableʤlistʤ
ʬ뤬ͤʤΤǡC++Environment֥Ȥ˳Ǽ롣
˺ƤC++Environment֥Ȥenvironment templateˤΤ
ɬפʤΤǡenvironment instanceˤϳǼʤ



 macro
macro褦ġĤȻפähygienicʽ񤭴뤿ˤϡ
bound줿ѿäƤΤץ˽񤱤ɬפ롣ʤΤǡ
evalidentifierɾbound줿ѿidentifier֤
ǽˤΤäݤ

Τˤϡޤ#<CLOSURE>θƤӽФʬĴɬפlambda
ɾ̤Ǥ#<PROCEDURE>#<CLOSURE>ϡ#<PROCEDURE>
ӽФ줿Ȥ˻ȤĶ(ܼŪˤbindingǤ褤)ͭ
ƤʤФʤʤ

ǤϥХȥѥ򤷤ƤʤΤǡlambdaɾƳ
#<PROCEDURE>bindƤѿ򤢤餫Τ뤳ȤǤʤ
Τᡢѿbinding򤳤δĶNܤslotȤ褦ɽ
뤳ȤǤʤ̿Ūʷ٤ʡǤʤƵƤӽФߤ
ʤȤԤslotɽ줿Ķ϶ͭǤʤġġ

#<CLOSURE>θƤӽФθľɬܤ
#<CLOSURE> AθƤӽФľδĶϡƤ#<CLOSURE> Abinding
ͭslot϶ͭʤȤǡ¤ˤɬפ롣

դbind_variable()ѻߤ
ͤʤbind_variable()assign_variable()Ȥ߹碌ƻȤȤ
ɬפ롣ޤ߹ʤȤ
TSCore::slot_value_in_env(binding)ѿͤɤ߹Ǥ뤬μ
Ŭ˽ɬפ롣



 R5RS
 Syntax

 4.1. Primitive expression types
4.1.1. Variable references
<variable>

4.1.2. Literal expressions
(quote <datum>)
'<datum>
<constant>

4.1.3. Procedure calls
(<operator> <operand1> ...)

4.1.4. Procedures
(lambda <formals> <body>)

4.1.5. Conditionals
(if <test> <consequent> <alternate>)
(if <test> <consequent>)

4.1.6. Assignments
(set! <variable> <expression>)


 4.2. Derived expression types
The constructs in this section are hygienic, as discussed in section 4.3

4.2.1. Conditionals
(cond <clause1> <clause2> ...)

Each <clause> should be of the form
(<test> <expression1> ...)
or
(<test> => <expression>)
or the last <clause> may be an
(else <expression1> <expression2> ...)

(case <clause1> <clause2> ...)

(and <test1> ...) : must do shortcircuit!
(or <test1> ...) : must do shortcircuit!

4.2.2. Binding constructs

(let <bindings> <body>)
<bindings> should have the form
((<variable1> <init1>) ...)
all <init>s are evaluated in the current environment, then <variable>s
are bound to fresh locations, visible from <body>, holding the results.
the value(s) of the last expression of <body> is(are) returned.

(let* <bindings> <body>)
similar to let, but the bindings are performed sequentially from left
toright, and the region of a binding indicated by (<variable> <init>)
is that part of the let* expression to the right of the binding.  Thus
the second binding is done in an environment in which the first
binding is visible, and so on.

(letrec <bindings> <body>)
The <variable>s are bound to fresh locations holding undefined values,
the <init>s are evaluated in the resulting environment (in some
unspecified order), each <variable> is assigned to the result of the
corresponding <init>, the <body> is evaluated in the resulting
environment, and the value(s) of the last expression in <body> is(are)
returned.  Each binding of a <variable> has the entire letrec
expression as its region.


4.2.3. Sequencing
(begin <expression1> <expression2> ...)

4.2.4. Iteration
!!! (do ((<variable1> <init1> <step1>)
!!!      ...)
!!!     (<test> <expression> ...)
!!!   <command> ...)
It specifies a set of variables to be bound, how they are to be
initialized at the start, and how they are to be updated on each
iteration.  When a termination condition is met, the loop exits after
evaluating the <expression>s.

Do expressions are evaluated as follows: The <init> expressions are
evaluated (in some unspecified order), the <variable>s are bound to
fresh locations, the results of the <init> expressions are stored in
the bindings of the <variable>s, and then the iteration phase begins.

Each iteration begins by evaluating <test>; if the result if false,
then the <command> expressions are evaluated in order for effect, the
<step> expressions are evaluated in some unspecified order, the
<variable>s are bound to fresh locations, the results of the <step>s
are stored in the bindings of the <variable>s, and the next iteration
begins.

If <test> evaluates to a true value, then the <expression>s are
evaluated from left to right and the value(s) of the last <expression>
is(are) returned.  If no <expression>s are present, then the value of
the do expression is unspecified.

The region of the binding of a <variable> consists of the entire do
expression except for the <init>s.

A <step> may be omitted, in which case the effect is the same as if
(<variable> <init> <variable>) had been written instead of
(<variable> <init>).


(let <variable> <bindings> <body>)
"Named let" is a variant on the syntax of let which provides a more
general looping construct than do and may also be used to express
recursions.  It has the same syntax and semantics as ordinary let
except that <variable> is bound within <body> to a procedure whose
formal arguments are the bound variables and whose body is <body>.
Thus the execution of <body> may be repeated by invoking the procedure
named by <variable>.


4.2.5. Delayed evaluation
(delay <expression>)


4.2.6. Quasiquotation
!!! (quasiquote <qq template>)
!!! `<qq template>


4.3. Macros
4.3.1. Binding constructs for syntactic keywords
!!! (let-syntax <bindings> <body>)
<bindings> should have the form
((<keyword> <transformer spec>) ...)
<keyword> is an identifier, each <transformer spec> is an instance of
syntax-rules, and <body> should be a sequence of one or more
expressions.

!!! (letrec-syntax <bindings> <body>)


let-syntaxξ硢<bindings>Ǥbinding(let-syntax)γ¦
bindingȤʤꡢletrec-syntaxξ硢<bindings>Ǥbinding
¦binding<bindings>ǳĥΤȤʤ롣



definedefine-syntaxsyntaxʤΤprocedureʤΤġġ
⡢ĶǤϤʤlexicalcontext˰¸ựѤΤǰ
syntaxprocedureǤϤʤ줬special formȸƤФƤ
Τ  gaucheǤϸݤsyntaxˤƤ褦


it is an error for a definition or syntax definition to shadow a
syntactic keyword whose meaning is needed to determine whether some
form in the group of forms that contains the shadowing definition is
in fact a definition, or, for internal definitions, is needed to
determine the boundary between the group and the expressions that
follow the group.  For example, the following are errors:

(define define 3)

(begin (define begin list))

(let-syntax
  ((foo (syntax-rules ()
          ((foo (proc args ...) body ...)
           (define proc
             (lambda (args ...)
               body ...))))))
  (let ((x 3))
    (foo (plus x y) (+ x y))
    (define foo x)
    (plus foo x)))



 Standard procedures

 6.1. Equivalence predicates
(eqv? obj1 obj2)
(eq? obj1 obj2)
(equal? obj1 obj2)

 6.2.5 Numerical operations
(number? obj)
!!! (complex? obj)
(real? obj)
!!! (rational? obj)
(integer? obj)

!!! (exact? z)
!!! (inexact? z)

(= z1 z2 z3 ...)
(< z1 z2 z3 ...)
(> z1 z2 z3 ...)
(<= z1 z2 z3 ...)
(>= z1 z2 z3 ...)

!!! (zero? z)
!!! (positive? x)
!!! (negative? x)
!!! (odd? n)
!!! (even? n)

!!! (max x1 x2 ...)
!!! (min x1 x2 ...)

(+ z1 ...)
(* z1 ...)
(- z1 z2)
(- z)
(- z1 z2 ...)
(/ z1 z2)
(/ z)
(/ z1 z2 ...)

(abs x)
(quotient n1 n2)
(remainder n1 n2)
(modulo n1 n2)

!!! (gcd n1 ...)
!!! (lcm n1 ...)

!!! (numerator q)
!!! (denominator q)

(floor x)
(ceiling x)
(truncate x)
(round x)

!!! (rationalize x y)

(exp z)
(log z)
(sin z)
(cos z)
(tan z)
(asin z)
(acos z)
(atan z)
(atan y x)

(sqrt z)
(expt z1 z2)

!!! (make-rectangular x1 x2)
!!! (make-polar x3 x4)
!!! (real-part z)
!!! (imag-part z)
!!! (magnitude z)
!!! (angle z)

!!! (exact->inexact z)
(inexact->exact z)

 6.2.6 Numerical input and output
!!! (number->string z)
!!! (number->string z radix)
!!! (string->number string)
!!! (string->number string radix)

 Other data types
 6.3.1 Booleans
(not obj)
(boolean? obj)

 6.3.2 Pairs and lists
(pair? obj)
(cons obj1 obj2)
(car pair)
(cdr pair)
(set-car! pair obj)
(set-cdr! pair obj)

!!! (caar pair)
!!! (cadr pair)
    ġ
!!! (cdddar pair)
!!! (cddddr pair)

(null? obj)
(list? obj)
!!! (list obj ...)
(length list)
(append list ...)
(reverse list)
!!! (list-tail list k)
!!! (list-ref list k)
!!! (memq obj list)
!!! (memv obj list)
!!! (member obj list)
(assq obj alist)
!!! (assv obj alist)
!!! (assoc obj alist)

 6.3.3 Symbols
(symbol? obj)
(symbol->string symbol)
(string->symbol string)
 string->symbolǺsymbolcase-sensitive

 6.3.4 Characters
(char? obj)
!!! (char=? char1 char2)
!!! (char<? char1 char2)
!!! (char>? char1 char2)
!!! (char<=? char1 char2)
!!! (char>=? char1 Char2)
!!! (char-ci=? char1 char2)
!!! (char-ci<? char1 char2)
!!! (char-ci>? char1 char2)
!!! (char-ci<=? char1 char2)
!!! (char-ci>=? char1 Char2)
(char-alphabetic? char)
(char-numeric? char)
(char-whitespace? char)
(char-upper-case? letter)
(char-lower-case? letter)
(char->integer char)
(integer->char n)
(char-upcase char)
(char-downcase char)

 6.3.5 Strings
(string? obj)
(make-string k)
(make-string k char)
(string char ...)
(string-length string)
(string-ref string k)
(string-set! string k char)
!!! (string=? string1 string2)
!!! (string-ci=? string1 string2)
!!! (string<? string1 string2)
!!! (string>? string1 string2)
!!! (string<=? string1 string2)
!!! (string>=? string1 string2)
!!! (string-ci<? string1 string2)
!!! (string-ci>? string1 string2)
!!! (string-ci<=? string1 string2)
!!! (string-ci>=? string1 string2)
(substring string start end)
(string-append string ...)
!!! (string->list string)
!!! (list->string list)
!!!(string-copy string)
(string-fill! string char)

 6.3.6 Vectors
(vector? obj)
(make-vector k)
(make-vector k fill)
(vector obj ...)
(vector-length vector)
(vector-ref vector k)
(vector-set! vector k obj)
!!! (vector->list vector)
!!! (list->vector list)


 6.4 Control features
(procedure? obj)
(apply proc arg1 ... args)
!!! (map proc list1 list2 ...)
!!! (for-each proc list1 list2 ...)
(force promise)
(call-with-current-continuation proc)
!!! (values obj ...)
!!! (call-with-values producer consumer)
!!! (dynamic-wind before thunk after)


 6.5 Eval
(eval expression environment-specifier)
(scheme-report-environment version)
(null-environment version)
(interaction-environment)


 6.6 Input and output
 6.6.1 Ports
!!! (call-with-input-file string proc)
!!! (call-with-output-file string proc)
(input-port? obj)
(output-port? obj)
(current-input-port)
(current-output-port)
!!! (with-input_from-file string thunk)
!!! (with-output-to-file string thunk)
(open-input-file filename)
(open-output-file filename)
(close-input-port port)
(close-output-port port)

 6.6.2 Input
(read)
(read port)
(read-char)
(read-char port)
(peek-char)
(peek-char port)
(eof-object? obj)
(char-ready?)
(char-ready? port)

 6.6.3 Output
(write obj)
(write obj port)
(display obj)
(display obj port)
(newline)
(newline port)
(write-char char)
(write-char char port)

 6.6.4 System interface
(load filename)
!!! (transcript-on filename)
!!! (transcript-off)



Хȥѥäsymbolic executionǼǤġĤȤꤢ
symbolicǤʤ̾execution¤褦ݥȤϡĶΰ
<variable>
ɾˡ󸽺ߤδĶ귫äslotõΤϼϼ
ǡslotĤäbinding餫ˤʤäˤ򻲾Ȥ
褦˥ץ񤭴ĤޤꡢƱץʣ¹Ԥ
硢٤Ǥunbound variableǤʤä硢<variable>bound
ƤslotSȤơ(variable_reference S of env)Ūʥץ˽
ƤޤʹߤϴĶθ򤵤ܤ롣(set! <variable>
<expression>)Ʊͤǡ(variable_store <expression> in S of env)Ūʥ
˽񤭴롣procedureƤӽФʤɤ٥뤬ۤʤ뤳Ȥ
Ʊͤ˽񤭴롣

nameޥsyntax-keywordǤ褦(name ...)eval硢
ޥŸΥץ(name ...)ʬ򡢶餯ޥŸ
̤ȤS֤Ƥޤ줫鹹Ÿ줿Sɾ
Ȥˤʤ롣


 evalܥ르ꥺ

: <datum>
: <datum>, [<datum>: 񤭴ץ]

<datum>constantʤ餽ϤȤ롣
<datum>(variable_reference S of env)ʤenvΥåSƤϤ
롣
<datum>symbolʤ鸽ߤδĶǤbindingĴ١syntaxbindƤ
顢syntax֥ȤϤȤ롣ĶenvΥåSvariable
bindƤ顢񤭴ץҤȤ
(variable_reference S of env)򥻥åȤѿƤϤȤ롣
bindƤʤϡunbound variable顼

<datum>ꥹPξ硢ꥹP1ܤ<operator>μ̤˱ư
Τ褦eval

<operator>ꥹQʤꥹQeval̤ꥹPΰܤǤ
ƥꥹP񤭴ꥹPevalľ
̯ʡġġꥹQeval̤ꥹȤä餽λǥ顼
  ˤ٤ʡ

<operator>#<PROCEDURE>ʤꥹPܰʹߤǤȤ
ƤӽФη̤ꥹPeval̤Ȥ롣

<operator>#<SYNTAX>ʤꥹPܰʹߤǤȤ
syntaxŬѤη̤ꥹPeval̤Ȥ롣

<operator>(variable_reference S of env)Ǥä顢envΥåS
ͤФ#<PROCEDURE>ʤꥹPܰʹߤǤȤƸ
ӽФη̤ꥹPeval̤Ȥ롣#<SYNTAX>Ǥä顢
#<SYNTAX>ꥹPΰܤǤȤƥꥹP񤭴ꥹP
evalľ
ѿ˳ǼƤͤ#<SYNTAX>ä饨顼ˤȤ
  ˤϤ뤬㤨С(define fake-and and)ߤʤΤػߤƤ
  ʤФʤʤƤʤ(fake-and ...)ʼɾ
  饨顼äƤΤǼΤ񤤤ǤϤʤ٤Ȥ񤤤Ƥ
  ȡ(define fake-and and)ѿfake-andbindͤȤandɾ
  ̤ǼΤʤΤǡ줬顼ˤʤʤäƤȤϡand
  ɾ̤եȥ饹֥Ȥ#<SYNTAX>ȤScheme
  鸫ȤȡդɬפʤΤ(apply <proc> <args>)
  applyȤƼproc#<PROCEDURE>ǤʤФʤʤ
  (apply-syntax <syntax> <args>)ߤʤΤȼĥȤ󶡤뤫
  Ȥơ(define fake-and and)ʤapply-syntaxŪ
  ɬפˤʤ롣

 ƱĶǡ뼱̻ҤФѿbindsyntaxbindȡ
 ̯ʾˤʤ롣ѿbindƤbindingФƤƤ
 Τϡμ̻ҤѿǤäȲꤷƤ롣餯夫syntax
 bindȤˡбѿͤȤƤ⡢bind줿syntax
 ֥ȤǼƤޤСʤreasonableʿ񤤤
 ε򸵤Ʊѿͤassign(set!)줿硢
 syntax bindingѿbinding򱣤Τerrorˤ٤
 Ƥset!åȤʤȡ(variable_reference S of env)Ū
 ΤƳͭߤ˾äƤޤۤɥȹ⡣
 syntaxbind줿ˤsymbolbindingĴ٤硢бƤ
 ѿƤɤäƤ⡢bindƤsyntax뤿ᡢ
 ̤ǤˤʤʤդˡsyntaxbindƤ̻Ҥ˿
 ѿbind硢syntaxؤbindingȤäƤץϡ
 bindƤsyntaxľ˻ȤƤϤʤΤѿbindľ
 Ȥ¤ˤϲαƶ⤦ʤ



<operator>symbolʤ鸽ߤδĶǤbindingĴ١syntaxbind
顢syntax(#<SYNTAX>)ꥹPΰܤǤȤƥꥹP
񤭴ꥹPevalľĶenvΥåSvariableȤ
bindƤ顢(variable_reference S of env)ꥹPΰܤ
ǤȤƥꥹP񤭴ꥹPevalľ




 ܥХȥ
load_constant			{ (constant:Cell *) }
load_variable			{ (env:Environment *), (slot:long) }
load_free_variable		{ (env:Environment *), (symbol:Cell *) }
store_variable			{ (env:Environment *), (slot:long) }
store_free_variable		{ (env:Environment *), (symbol:Cell *) }

lambda				{ (env:Environment *), (code:Cell *) }


// CONTROLS
return				{ 0 }	// Ĥopcode=0˳

apply				{ ? }


// PREDICATES
boolean?			{ 1 }

char?				{ 1 }
	char-alphabetic?	{ 1 }
	char-lower-case?	{ 1 }
	char-numeric?		{ 1 }
	char-upper-case?	{ 1 }
	char-whitespace?	{ 1 }

number?				{ 1 }
	complex?		{ 1 }
	exact?			{ 1 }
	inexact?		{ 1 }
	integer?		{ 1 }
	negative?		{ 1 }
	even?			{ 1 }
	odd?			{ 1 }
	rational?		{ 1 }
	real?			{ 1 }
	zero?			{ 1 }

eof-object?			{ 1 }

list?				{ 1 }

null?				{ 1 }

pair?				{ 1 }

port?				{ 1 }
	input-port?		{ 1 }
	output-port?		{ 1 }

procedure?			{ 1 }

regexp?				{ 1 }

string?				{ 1 }

symbol?				{ 1 }

vector?				{ 1 }


// CONS
cons				{ 2 }
car				{ 1 }
cdr				{ 1 }
set-car!			{ 2 }
set-cdr!			{ 2 }

