Using literals vocab for defining computed constants

db4
Alex Chapman 2009-04-20 14:15:38 +10:00
parent dac233992a
commit 0e6f76c13d
2 changed files with 62 additions and 68 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007, 2008 Alex Chapman ! Copyright (C) 2007, 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays colors combinators kernel locals math math.constants math.matrices math.order math.ranges math.vectors math.quadratic random sequences specialized-arrays.float vectors jamshred.oint ; USING: accessors arrays colors combinators kernel literals locals math math.constants math.matrices math.order math.ranges math.vectors math.quadratic random sequences specialized-arrays.float vectors jamshred.oint ;
IN: jamshred.tunnel IN: jamshred.tunnel
CONSTANT: n-segments 5000 CONSTANT: n-segments 5000
@ -15,9 +15,7 @@ C: <segment> segment
{ 100 100 100 } [ random 100 / >float ] map first3 1.0 <rgba> ; { 100 100 100 } [ random 100 / >float ] map first3 1.0 <rgba> ;
CONSTANT: tunnel-segment-distance 0.4 CONSTANT: tunnel-segment-distance 0.4
USE: words.constant CONSTANT: random-rotation-angle $[ pi 20 / ]
DEFER: random-rotation-angle
\ random-rotation-angle pi 20 / define-constant
: random-segment ( previous-segment -- segment ) : random-segment ( previous-segment -- segment )
clone dup random-rotation-angle random-turn clone dup random-rotation-angle random-turn

View File

@ -1,7 +1,6 @@
! Copyright (C) 2007, 2008, 2009 Alex Chapman, 2009 Diego Martinelli ! Copyright (C) 2007, 2008, 2009 Alex Chapman, 2009 Diego Martinelli
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors ascii assocs biassocs combinators hashtables kernel lists math USING: accessors ascii assocs biassocs combinators hashtables kernel lists literals math namespaces make multiline openal parser sequences splitting strings synth synth.buffers ;
namespaces make multiline openal parser sequences splitting strings synth synth.buffers ;
IN: morse IN: morse
<PRIVATE <PRIVATE
@ -14,68 +13,65 @@ CONSTANT: unknown-char CHAR: ?
PRIVATE> PRIVATE>
DEFER: morse-code-table CONSTANT: morse-code-table $[
H{
H{ { CHAR: a ".-" }
{ CHAR: a ".-" } { CHAR: b "-..." }
{ CHAR: b "-..." } { CHAR: c "-.-." }
{ CHAR: c "-.-." } { CHAR: d "-.." }
{ CHAR: d "-.." } { CHAR: e "." }
{ CHAR: e "." } { CHAR: f "..-." }
{ CHAR: f "..-." } { CHAR: g "--." }
{ CHAR: g "--." } { CHAR: h "...." }
{ CHAR: h "...." } { CHAR: i ".." }
{ CHAR: i ".." } { CHAR: j ".---" }
{ CHAR: j ".---" } { CHAR: k "-.-" }
{ CHAR: k "-.-" } { CHAR: l ".-.." }
{ CHAR: l ".-.." } { CHAR: m "--" }
{ CHAR: m "--" } { CHAR: n "-." }
{ CHAR: n "-." } { CHAR: o "---" }
{ CHAR: o "---" } { CHAR: p ".--." }
{ CHAR: p ".--." } { CHAR: q "--.-" }
{ CHAR: q "--.-" } { CHAR: r ".-." }
{ CHAR: r ".-." } { CHAR: s "..." }
{ CHAR: s "..." } { CHAR: t "-" }
{ CHAR: t "-" } { CHAR: u "..-" }
{ CHAR: u "..-" } { CHAR: v "...-" }
{ CHAR: v "...-" } { CHAR: w ".--" }
{ CHAR: w ".--" } { CHAR: x "-..-" }
{ CHAR: x "-..-" } { CHAR: y "-.--" }
{ CHAR: y "-.--" } { CHAR: z "--.." }
{ CHAR: z "--.." } { CHAR: 1 ".----" }
{ CHAR: 1 ".----" } { CHAR: 2 "..---" }
{ CHAR: 2 "..---" } { CHAR: 3 "...--" }
{ CHAR: 3 "...--" } { CHAR: 4 "....-" }
{ CHAR: 4 "....-" } { CHAR: 5 "....." }
{ CHAR: 5 "....." } { CHAR: 6 "-...." }
{ CHAR: 6 "-...." } { CHAR: 7 "--..." }
{ CHAR: 7 "--..." } { CHAR: 8 "---.." }
{ CHAR: 8 "---.." } { CHAR: 9 "----." }
{ CHAR: 9 "----." } { CHAR: 0 "-----" }
{ CHAR: 0 "-----" } { CHAR: . ".-.-.-" }
{ CHAR: . ".-.-.-" } { CHAR: , "--..--" }
{ CHAR: , "--..--" } { CHAR: ? "..--.." }
{ CHAR: ? "..--.." } { CHAR: ' ".----." }
{ CHAR: ' ".----." } { CHAR: ! "-.-.--" }
{ CHAR: ! "-.-.--" } { CHAR: / "-..-." }
{ CHAR: / "-..-." } { CHAR: ( "-.--." }
{ CHAR: ( "-.--." } { CHAR: ) "-.--.-" }
{ CHAR: ) "-.--.-" } { CHAR: & ".-..." }
{ CHAR: & ".-..." } { CHAR: : "---..." }
{ CHAR: : "---..." } { CHAR: ; "-.-.-." }
{ CHAR: ; "-.-.-." } { CHAR: = "-...- " }
{ CHAR: = "-...- " } { CHAR: + ".-.-." }
{ CHAR: + ".-.-." } { CHAR: - "-....-" }
{ CHAR: - "-....-" } { CHAR: _ "..--.-" }
{ CHAR: _ "..--.-" } { CHAR: " ".-..-." }
{ CHAR: " ".-..-." } { CHAR: $ "...-..-" }
{ CHAR: $ "...-..-" } { CHAR: @ ".--.-." }
{ CHAR: @ ".--.-." } { CHAR: \s "/" }
{ CHAR: \s "/" } } >biassoc
} >biassoc \ morse-code-table set-global ]
: morse-code-table ( -- biassoc )
\ morse-code-table get-global ;
: ch>morse ( ch -- morse ) : ch>morse ( ch -- morse )
ch>lower morse-code-table at [ unknown-char ] unless* ; ch>lower morse-code-table at [ unknown-char ] unless* ;