unicode.syntax.backend => value (with docs &c)
parent
2e796f8431
commit
c04da7bdfb
|
@ -1,8 +1,8 @@
|
||||||
! Copyright (C) 2008 Daniel Ehrenberg
|
! Copyright (C) 2008 Daniel Ehrenberg
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel strings unicode.syntax.backend io.files assocs
|
USING: kernel strings values io.files assocs
|
||||||
splitting sequences io namespaces sets
|
splitting sequences io namespaces sets io.encodings.8-bit
|
||||||
io.encodings.ascii io.encodings.utf8 io.encodings.utf16 io.encodings.8-bit ;
|
io.encodings.ascii io.encodings.utf8 io.encodings.utf16 ;
|
||||||
IN: io.encodings.iana
|
IN: io.encodings.iana
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
USING: unicode.categories kernel math combinators splitting
|
USING: unicode.categories kernel math combinators splitting
|
||||||
sequences math.parser io.files io assocs arrays namespaces
|
sequences math.parser io.files io assocs arrays namespaces
|
||||||
math.ranges unicode.normalize unicode.syntax.backend
|
math.ranges unicode.normalize values io.encodings.ascii
|
||||||
unicode.syntax unicode.data compiler.units alien.syntax io.encodings.ascii ;
|
unicode.syntax unicode.data compiler.units alien.syntax ;
|
||||||
IN: unicode.breaks
|
IN: unicode.breaks
|
||||||
|
|
||||||
C-ENUM: Any L V T Extend Control CR LF graphemes ;
|
C-ENUM: Any L V T Extend Control CR LF graphemes ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
USING: assocs math kernel sequences io.files hashtables
|
USING: assocs math kernel sequences io.files hashtables
|
||||||
quotations splitting arrays math.parser hash2 math.order
|
quotations splitting arrays math.parser hash2 math.order
|
||||||
byte-arrays words namespaces words compiler.units parser
|
byte-arrays words namespaces words compiler.units parser
|
||||||
io.encodings.ascii unicode.syntax.backend ;
|
io.encodings.ascii values ;
|
||||||
IN: unicode.data
|
IN: unicode.data
|
||||||
|
|
||||||
! Convenience functions
|
! Convenience functions
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: unicode.syntax.backend kernel sequences assocs io.files
|
USING: values kernel sequences assocs io.files
|
||||||
io.encodings ascii math.ranges io splitting math.parser
|
io.encodings ascii math.ranges io splitting math.parser
|
||||||
namespaces byte-arrays locals math sets io.encodings.ascii
|
namespaces byte-arrays locals math sets io.encodings.ascii
|
||||||
words compiler.units arrays interval-maps ;
|
words compiler.units arrays interval-maps ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Daniel Ehrenberg
|
|
@ -0,0 +1 @@
|
||||||
|
Global variables in the Forth value style
|
|
@ -0,0 +1 @@
|
||||||
|
extensions
|
|
@ -0,0 +1,27 @@
|
||||||
|
USING: help.markup help.syntax ;
|
||||||
|
IN: values
|
||||||
|
|
||||||
|
ARTICLE: "values" "Global values"
|
||||||
|
"Usually, dynamically scoped variables are sufficient for holding data which is not literal. But occasionally, for global information that's calculated just once, it's useful to use the word mechanism instead, and set the word to the appropriate value just once. Values abstract over this concept. To create a new word as a value, use the following syntax:"
|
||||||
|
{ $subsection POSTPONE: VALUE: }
|
||||||
|
"To get the value, just call the word. The following words manipulate values:"
|
||||||
|
{ $subsection get-value }
|
||||||
|
{ $subsection set-value }
|
||||||
|
{ $subsection change-value } ;
|
||||||
|
|
||||||
|
HELP: VALUE:
|
||||||
|
{ $syntax "VALUE: word" }
|
||||||
|
{ $values { "word" "a word to be created" } }
|
||||||
|
{ $description "Creates a value on the given word, initializing it to hold " { $code f } ". To get the value, just run the word. To set it, use " { $link set-value } "." } ;
|
||||||
|
|
||||||
|
HELP: get-value
|
||||||
|
{ $values { "word" "a value word" } { "value" "the contents" } }
|
||||||
|
{ $description "Gets a value. This should not normally be used, unless the word is not known until runtime." } ;
|
||||||
|
|
||||||
|
HELP: set-value
|
||||||
|
{ $values { "value" "a new value" } { "word" "a value word" } }
|
||||||
|
{ $description "Sets the value word." } ;
|
||||||
|
|
||||||
|
HELP: change-value
|
||||||
|
{ $values { "word" "a value word" } { "quot" "a quotation ( oldvalue -- newvalue )" } }
|
||||||
|
{ $description "Changes the value using the given quotation." } ;
|
|
@ -0,0 +1,9 @@
|
||||||
|
USING: tools.test values math ;
|
||||||
|
IN: values.tests
|
||||||
|
|
||||||
|
VALUE: foo
|
||||||
|
[ f ] [ foo ] unit-test
|
||||||
|
[ ] [ 3 \ foo set-value ] unit-test
|
||||||
|
[ 3 ] [ foo ] unit-test
|
||||||
|
[ ] [ \ foo [ 1+ ] change-value ] unit-test
|
||||||
|
[ 4 ] [ foo ] unit-test
|
8
extra/unicode/syntax/backend/backend.factor → extra/values/values.factor
Normal file → Executable file
8
extra/unicode/syntax/backend/backend.factor → extra/values/values.factor
Normal file → Executable file
|
@ -1,8 +1,14 @@
|
||||||
USING: kernel parser sequences words ;
|
USING: kernel parser sequences words ;
|
||||||
IN: unicode.syntax.backend
|
IN: values
|
||||||
|
|
||||||
: VALUE:
|
: VALUE:
|
||||||
CREATE-WORD { f } clone [ first ] curry define ; parsing
|
CREATE-WORD { f } clone [ first ] curry define ; parsing
|
||||||
|
|
||||||
: set-value ( value word -- )
|
: set-value ( value word -- )
|
||||||
word-def first set-first ;
|
word-def first set-first ;
|
||||||
|
|
||||||
|
: get-value ( word -- value )
|
||||||
|
word-def first first ;
|
||||||
|
|
||||||
|
: change-value ( word quot -- )
|
||||||
|
over >r >r get-value r> call r> set-value ; inline
|
Loading…
Reference in New Issue