]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' into experimental
authorAlex Chapman <chapman.alex@gmail.com>
Mon, 20 Apr 2009 02:21:54 +0000 (12:21 +1000)
committerAlex Chapman <chapman.alex@gmail.com>
Mon, 20 Apr 2009 02:21:54 +0000 (12:21 +1000)
core/syntax/syntax-docs.factor
extra/jamshred/game/game.factor
extra/jamshred/gl/gl.factor
extra/jamshred/jamshred.factor
extra/jamshred/player/player.factor
extra/jamshred/tunnel/tunnel.factor
extra/morse/authors.txt
extra/morse/morse-docs.factor
extra/morse/morse-tests.factor
extra/morse/morse.factor
extra/synth/buffers/buffers.factor

index 33a0096ff9324a8f7564562d00b397bb5986ce68..f869cff50614f308caabd1e1010cdc84d8d9ca06 100644 (file)
@@ -526,10 +526,10 @@ HELP: ((
 { $notes "Useful for meta-programming with " { $link define-declared } "." }
 { $examples
     { $code
-        "SYMBOL: my-dynamic-word"
+        "<< SYMBOL: my-dynamic-word"
         "USING: math random words ;"
-        "3 { [ + ] [ - ] [ * ] [ / ] } random curry"
-        "(( x -- y )) define-declared"
+        "my-dynamic-word 3 { [ + ] [ - ] [ * ] [ / ] } random curry"
+        "(( x -- y )) define-declared >>"
     }
 } ;
 
@@ -789,4 +789,4 @@ HELP: execute(
 { $syntax "execute( stack -- effect )" }
 { $description "Calls the word on the top of the stack, asserting that it has the given stack effect. The word does not need to be known at compile time." } ;
 
-{ POSTPONE: call( POSTPONE: execute( } related-words
\ No newline at end of file
+{ POSTPONE: call( POSTPONE: execute( } related-words
index 9cb5bc7c3aab29866a841242c9f4e7502306ada9..14bf18a9c1644085f46b93e6a7234873255b6448 100644 (file)
@@ -29,7 +29,7 @@ TUPLE: jamshred sounds tunnel players running quit ;
 : mouse-moved ( x-radians y-radians jamshred -- )
     jamshred-player -rot turn-player ;
 
-: units-per-full-roll ( -- n ) 50 ;
+CONSTANT: units-per-full-roll 50
 
 : jamshred-roll ( jamshred n -- )
     [ jamshred-player ] dip 2 pi * * units-per-full-roll / roll-player ;
index bae275e96a52fe3d0fa4a5e7e568529c35ed6fcc..a1d22c48dc548e715b3ba34e0427f6a74d84ff0e 100644 (file)
@@ -6,18 +6,17 @@ math.functions math.vectors opengl opengl.gl opengl.glu
 opengl.demo-support sequences specialized-arrays.float ;
 IN: jamshred.gl
 
-: min-vertices ( -- n ) 6 ; inline
-: max-vertices ( -- n ) 32 ; inline
+CONSTANT: min-vertices 6
+CONSTANT: max-vertices 32
 
-: n-vertices ( -- n ) 32 ; inline
+CONSTANT: n-vertices 32
 
 ! render enough of the tunnel that it looks continuous
-: n-segments-ahead ( -- n ) 60 ; inline
-: n-segments-behind ( -- n ) 40 ; inline
+CONSTANT: n-segments-ahead 60
+CONSTANT: n-segments-behind 40
 
-: wall-drawing-offset ( -- n )
-    #! so that we can't see through the wall, we draw it a bit further away
-    0.15 ;
+! so that we can't see through the wall, we draw it a bit further away
+CONSTANT: wall-drawing-offset 0.15
 
 : wall-drawing-radius ( segment -- r )
     radius>> wall-drawing-offset + ;
index 49624e29470bb07f780c2433953d4bbcb618c7e3..fd683e3bc4e74545e2c7cb87ea613cee2420a7f3 100644 (file)
@@ -8,8 +8,8 @@ TUPLE: jamshred-gadget < gadget { jamshred jamshred } last-hand-loc ;
 : <jamshred-gadget> ( jamshred -- gadget )
     jamshred-gadget new swap >>jamshred ;
 
-: default-width ( -- x ) 800 ;
-: default-height ( -- y ) 600 ;
+CONSTANT: default-width 800
+CONSTANT: default-height 600
 
 M: jamshred-gadget pref-dim*
     drop default-width default-height 2array ;
index d33b78f29c8ad1608a84c7e1cac58040d9ef45fc..5b92b3a43495190aec227e74c78bb4a16c44f515 100644 (file)
@@ -12,8 +12,8 @@ TUPLE: player < oint
     { speed float } ;
 
 ! speeds are in GL units / second
-: default-speed ( -- speed ) 1.0 ;
-: max-speed ( -- speed ) 30.0 ;
+CONSTANT: default-speed 1.0
+CONSTANT: max-speed 30.0
 
 : <player> ( name sounds -- player )
     [ float-array{ 0 0 5 } float-array{ 0 0 -1 } float-array{ 0 1 0 } float-array{ -1 0 0 } ] 2dip
index 4c4b3e6812f9bb2c558cb07208a7fed5591a2b99..d951a37f0c9fb88292a5ed87d0e930f05a8445a7 100644 (file)
@@ -3,7 +3,7 @@
 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 ;
 IN: jamshred.tunnel
 
-: n-segments ( -- n ) 5000 ; inline
+CONSTANT: n-segments 5000
 
 TUPLE: segment < oint number color radius ;
 C: <segment> segment
@@ -14,8 +14,10 @@ C: <segment> segment
 : random-color ( -- color )
     { 100 100 100 } [ random 100 / >float ] map first3 1.0 <rgba> ;
 
-: tunnel-segment-distance ( -- n ) 0.4 ;
-: random-rotation-angle ( -- theta ) pi 20 / ;
+CONSTANT: tunnel-segment-distance 0.4
+USE: words.constant
+DEFER: random-rotation-angle
+\ random-rotation-angle pi 20 / define-constant
 
 : random-segment ( previous-segment -- segment )
     clone dup random-rotation-angle random-turn
@@ -27,7 +29,7 @@ C: <segment> segment
         [ dup peek random-segment over push ] dip 1- (random-segments)
     ] [ drop ] if ;
 
-: default-segment-radius ( -- r ) 1 ;
+CONSTANT: default-segment-radius 1
 
 : initial-segment ( -- segment )
     float-array{ 0 0 0 } float-array{ 0 0 -1 } float-array{ 0 1 0 } float-array{ -1 0 0 }
@@ -115,7 +117,7 @@ C: <segment> segment
 : wall-normal ( seg oint -- n )
     location>> vector-to-centre normalize ;
 
-: distant ( -- n ) 1000 ;
+CONSTANT: distant 1000
 
 : max-real ( a b -- c )
     #! sometimes collision-coefficient yields complex roots, so we ignore these (hack)
index e9c193bac72836f0710fc5440af248256e9fc736..409f0443a67557e80e3abf087400cb6393ec519c 100644 (file)
@@ -1 +1,2 @@
 Alex Chapman
+Diego Martinelli
index e35967d3e965e85f5703f8faa547991241e8686d..93350ad02d3da97bb49ad328bd43ca864e6dd8db 100644 (file)
@@ -6,12 +6,12 @@ IN: morse
 HELP: ch>morse
 { $values
     { "ch" "A character that has a morse code translation" } { "str" "A string consisting of zero or more dots and dashes" } }
-{ $description "If the given character has a morse code translation, then return that translation, otherwise return an empty string." } ;
+{ $description "If the given character has a morse code translation, then return that translation, otherwise return a ? character." } ;
 
 HELP: morse>ch
 { $values
     { "str" "A string of dots and dashes that represents a single character in morse code" } { "ch" "The translated character" } }
-{ $description "If the given string represents a morse code character, then return that character, otherwise return f" } ;
+{ $description "If the given string represents a morse code character, then return that character, otherwise return a space character." } ;
 
 HELP: >morse
 { $values
index 144448917f3e3d10ac432952c7d77cda49d81925..fd52df1c4d54987bf06ca7fe78e480c9554d04b6 100644 (file)
@@ -1,13 +1,43 @@
 ! Copyright (C) 2007 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays morse strings tools.test ;
+IN: morse.tests
 
-[ "" ] [ CHAR: \\ ch>morse ] unit-test
+[ CHAR: ? ] [ CHAR: \\ ch>morse ] unit-test
 [ "..." ] [ CHAR: s ch>morse ] unit-test
 [ CHAR: s ] [ "..." morse>ch ] unit-test
-[ f ] [ "..--..--.." morse>ch ] unit-test
+[ CHAR: \s ] [ "..--..--.." morse>ch ] unit-test
 [ "-- --- .-. ... . / -.-. --- -.. ." ] [ "morse code" >morse ] unit-test
 [ "morse code" ] [ "-- --- .-. ... . / -.-. --- -.. ." morse> ] unit-test
 [ "hello, world!" ] [ "Hello, World!" >morse morse> ] unit-test
+[ ".- -... -.-." ] [ "abc" >morse ] unit-test
+
+[ "abc" ] [ ".- -... -.-." morse> ] unit-test
+
+[ "morse code" ] [
+    [MORSE
+        -- --- .-. ... . /
+        -.-. --- -.. .
+    MORSE] >morse morse> ] unit-test
+
+[ "morse code 123" ] [
+    [MORSE
+        __ ___ ._. ... . / 
+        _._. ___ _.. . / 
+        .____ ..___ ...__
+    MORSE] ] unit-test
+
+[ [MORSE
+      -- --- .-. ... . /
+      -.-. --- -.. .
+  MORSE] ] [
+    "morse code" >morse morse> 
+] unit-test
+
+[ "factor rocks!" ] [
+    [MORSE
+      ..-. .- -.-. - --- .-. / 
+      .-. --- -.-. -.- ... -.-.--
+    MORSE] ] unit-test
 ! [ ] [ "sos" 0.075 play-as-morse* ] unit-test
 ! [ ] [ "Factor rocks!" play-as-morse ] unit-test
index 54abce93953808f9a3e0835987d6a5942238cf28..49e6ae39f594355eda6e3cb7c75904fb8b4bfd51 100644 (file)
-! Copyright (C) 2007, 2008 Alex Chapman
+! Copyright (C) 2007, 2008, 2009 Alex Chapman, 2009 Diego Martinelli
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors ascii assocs combinators hashtables kernel lists math
-namespaces make openal parser-combinators promises sequences
-strings synth synth.buffers unicode.case ;
+USING: accessors ascii assocs biassocs combinators hashtables kernel lists math
+namespaces make multiline openal parser sequences splitting strings synth synth.buffers ;
 IN: morse
 
 <PRIVATE
-: morse-codes ( -- array )
-    {
-        { CHAR: a ".-"    }
-        { CHAR: b "-..."  }
-        { CHAR: c "-.-."  }
-        { CHAR: d "-.."   }
-        { CHAR: e "."     }
-        { CHAR: f "..-."  }
-        { CHAR: g "--."   }
-        { CHAR: h "...."  }
-        { CHAR: i ".."    }
-        { CHAR: j ".---"  }
-        { CHAR: k "-.-"   }
-        { CHAR: l ".-.."  }
-        { CHAR: m "--"    }
-        { CHAR: n "-."    }
-        { CHAR: o "---"   }
-        { CHAR: p ".--."  }
-        { CHAR: q "--.-"  }
-        { CHAR: r ".-."   }
-        { CHAR: s "..."   }
-        { CHAR: t "-"     }
-        { CHAR: u "..-"   }
-        { CHAR: v "...-"  }
-        { CHAR: w ".--"   }
-        { CHAR: x "-..-"  }
-        { CHAR: y "-.--"  }
-        { CHAR: z "--.."  }
-        { CHAR: 1 ".----" }
-        { CHAR: 2 "..---" }
-        { CHAR: 3 "...--" }
-        { CHAR: 4 "....-" }
-        { CHAR: 5 "....." }
-        { CHAR: 6 "-...." }
-        { CHAR: 7 "--..." }
-        { CHAR: 8 "---.." }
-        { CHAR: 9 "----." }
-        { CHAR: 0 "-----" }
-        { CHAR: . ".-.-.-" }
-        { CHAR: , "--..--" }
-        { CHAR: ? "..--.." }
-        { CHAR: ' ".----." }
-        { CHAR: ! "-.-.--" }
-        { CHAR: / "-..-."  }
-        { CHAR: ( "-.--."  }
-        { CHAR: ) "-.--.-" }
-        { CHAR: & ".-..."  }
-        { CHAR: : "---..." }
-        { CHAR: ; "-.-.-." }
-        { CHAR: = "-...- " }
-        { CHAR: + ".-.-."  }
-        { CHAR: - "-....-" }
-        { CHAR: _ "..--.-" }
-        { CHAR: " ".-..-." }
-        { CHAR: $ "...-..-" }
-        { CHAR: @ ".--.-." }
-        { CHAR: \s "/" }
-    } ;
-
-: ch>morse-assoc ( -- assoc )
-    morse-codes >hashtable ;
-
-: morse>ch-assoc ( -- assoc )
-    morse-codes [ reverse ] map >hashtable ;
+
+CONSTANT: dot-char CHAR: .
+CONSTANT: dash-char CHAR: -
+CONSTANT: char-gap-char CHAR: \s
+CONSTANT: word-gap-char CHAR: /
+CONSTANT: unknown-char CHAR: ?
 
 PRIVATE>
 
-: ch>morse ( ch -- str )
-    ch>lower ch>morse-assoc at* swap "" ? ;
+DEFER: morse-code-table
+
+H{
+    { CHAR: a ".-"    }
+    { CHAR: b "-..."  }
+    { CHAR: c "-.-."  }
+    { CHAR: d "-.."   }
+    { CHAR: e "."     }
+    { CHAR: f "..-."  }
+    { CHAR: g "--."   }
+    { CHAR: h "...."  }
+    { CHAR: i ".."    }
+    { CHAR: j ".---"  }
+    { CHAR: k "-.-"   }
+    { CHAR: l ".-.."  }
+    { CHAR: m "--"    }
+    { CHAR: n "-."    }
+    { CHAR: o "---"   }
+    { CHAR: p ".--."  }
+    { CHAR: q "--.-"  }
+    { CHAR: r ".-."   }
+    { CHAR: s "..."   }
+    { CHAR: t "-"     }
+    { CHAR: u "..-"   }
+    { CHAR: v "...-"  }
+    { CHAR: w ".--"   }
+    { CHAR: x "-..-"  }
+    { CHAR: y "-.--"  }
+    { CHAR: z "--.."  }
+    { CHAR: 1 ".----" }
+    { CHAR: 2 "..---" }
+    { CHAR: 3 "...--" }
+    { CHAR: 4 "....-" }
+    { CHAR: 5 "....." }
+    { CHAR: 6 "-...." }
+    { CHAR: 7 "--..." }
+    { CHAR: 8 "---.." }
+    { CHAR: 9 "----." }
+    { CHAR: 0 "-----" }
+    { CHAR: . ".-.-.-" }
+    { CHAR: , "--..--" }
+    { CHAR: ? "..--.." }
+    { CHAR: ' ".----." }
+    { CHAR: ! "-.-.--" }
+    { CHAR: / "-..-."  }
+    { CHAR: ( "-.--."  }
+    { CHAR: ) "-.--.-" }
+    { CHAR: & ".-..."  }
+    { CHAR: : "---..." }
+    { CHAR: ; "-.-.-." }
+    { CHAR: = "-...- " }
+    { CHAR: + ".-.-."  }
+    { CHAR: - "-....-" }
+    { CHAR: _ "..--.-" }
+    { CHAR: " ".-..-." }
+    { CHAR: $ "...-..-" }
+    { CHAR: @ ".--.-." }
+    { CHAR: \s "/" }
+} >biassoc \ morse-code-table set-global
+
+: morse-code-table ( -- biassoc )
+    \ morse-code-table get-global ;
+
+: ch>morse ( ch -- morse )
+    ch>lower morse-code-table at [ unknown-char ] unless* ;
 
 : morse>ch ( str -- ch )
-    morse>ch-assoc at* swap f ? ;
-
-: >morse ( str -- str )
-    [
-        [ CHAR: \s , ] [ ch>morse % ] interleave
-    ] "" make ;
-
+    morse-code-table value-at [ char-gap-char ] unless* ;
+    
 <PRIVATE
+    
+: word>morse ( str -- morse )
+    [ ch>morse ] { } map-as " " join ;
 
-: dot-char ( -- ch ) CHAR: . ;
-: dash-char ( -- ch ) CHAR: - ;
-: char-gap-char ( -- ch ) CHAR: \s ;
-: word-gap-char ( -- ch ) CHAR: / ;
-
-: =parser ( obj -- parser )
-    [ = ] curry satisfy ;
+: sentence>morse ( str -- morse )
+    " " split [ word>morse ] map " / " join ;
+    
+: trim-blanks ( str -- newstr )
+    [ blank? ] trim ; inline
 
-LAZY: 'dot' ( -- parser )
-    dot-char =parser ;
+: morse>word ( morse -- str )
+    " " split [ morse>ch ] "" map-as ;
 
-LAZY: 'dash' ( -- parser )
-    dash-char =parser ;
+: morse>sentence ( morse -- sentence )
+    "/" split [ trim-blanks morse>word ] map " " join ;
 
-LAZY: 'char-gap' ( -- parser )
-    char-gap-char =parser ;
-
-LAZY: 'word-gap' ( -- parser )
-    word-gap-char =parser ;
-
-LAZY: 'morse-char' ( -- parser )
-    'dot' 'dash' <|> <+> ;
-
-LAZY: 'morse-word' ( -- parser )
-    'morse-char' 'char-gap' list-of ;
-
-LAZY: 'morse-words' ( -- parser )
-    'morse-word' 'word-gap' list-of ;
+: replace-underscores ( str -- str' )
+    [ dup CHAR: _ = [ drop CHAR: - ] when ] map ;
 
 PRIVATE>
-
-: morse> ( str -- str )
-    'morse-words' parse car parsed>> [
-        [ 
-            >string morse>ch
-        ] map >string
-    ] map [ [ CHAR: \s , ] [ % ] interleave ] "" make ;
-
+    
+: >morse ( str -- newstr )
+    trim-blanks sentence>morse ;
+    
+: morse> ( morse -- plain )
+    replace-underscores morse>sentence ;
+
+SYNTAX: [MORSE "MORSE]" parse-multiline-string morse> parsed ; 
+    
 <PRIVATE
+    
 SYMBOLS: source dot-buffer dash-buffer intra-char-gap-buffer letter-gap-buffer ;
 
 : queue ( symbol -- )
@@ -135,7 +125,7 @@ SYMBOLS: source dot-buffer dash-buffer intra-char-gap-buffer letter-gap-buffer ;
 : intra-char-gap ( -- ) intra-char-gap-buffer queue ;
 : letter-gap ( -- ) letter-gap-buffer queue ;
 
-: beep-freq ( -- n ) 880 ;
+CONSTANT: beep-freq 880
 
 : <morse-buffer> ( -- buffer )
     half-sample-freq <8bit-mono-buffer> ;
index 671ebead63fb72b4764bf6a3cb8a209f0e39bf88..4c0ef6460745c129d84c43533a2691eda1825e35 100644 (file)
@@ -57,11 +57,11 @@ M: 8bit-stereo-buffer buffer-data
 M: 16bit-stereo-buffer buffer-data
     interleaved-stereo-data 16bit-buffer-data ;
 
-: telephone-sample-freq ( -- n ) 8000 ;
-: half-sample-freq ( -- n ) 22050 ;
-: cd-sample-freq ( -- n ) 44100 ;
-: digital-sample-freq ( -- n ) 48000 ;
-: professional-sample-freq ( -- n ) 88200 ;
+CONSTANT: telephone-sample-freq 8000
+CONSTANT: half-sample-freq 22050
+CONSTANT: cd-sample-freq 44100
+CONSTANT: digital-sample-freq 48000
+CONSTANT: professional-sample-freq 88200
 
 : send-buffer ( buffer -- buffer )
     {