From 13cf80c0c7fa6a8935ca99ed09278e57aee64ad0 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Fri, 24 Jul 2009 15:33:45 +1200 Subject: [PATCH 1/4] alien.inline.syntax: changed RAW-C: to " } +{ $description "Insert a (multiline) string into the generated source file. Useful for macros and other details not implemented in " { $snippet "alien.inline" } "." } ; diff --git a/extra/alien/inline/syntax/syntax.factor b/extra/alien/inline/syntax/syntax.factor index 6cef56f9b2..ce18616bc3 100644 --- a/extra/alien/inline/syntax/syntax.factor +++ b/extra/alien/inline/syntax/syntax.factor @@ -28,4 +28,4 @@ SYNTAX: ;C-LIBRARY compile-c-library ; SYNTAX: DELETE-C-LIBRARY: scan delete-inline-library ; -SYNTAX: RAW-C: parse-here raw-c ; +SYNTAX: " parse-multiline-string raw-c ; From abf1ae47025baa84dbab388a63639b6c27e9ad94 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Fri, 24 Jul 2009 18:24:27 +1200 Subject: [PATCH 2/4] alien.inline: define-c-library: set "c-library" --- extra/alien/inline/inline.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/alien/inline/inline.factor b/extra/alien/inline/inline.factor index 62c6102a86..84c3450102 100644 --- a/extra/alien/inline/inline.factor +++ b/extra/alien/inline/inline.factor @@ -65,7 +65,7 @@ PRIVATE> concat make-function ; : define-c-library ( name -- ) - c-library-name c-library set + c-library-name [ c-library set ] [ "c-library" set ] bi V{ } clone c-strings set V{ } clone linker-args set ; From c458904fd7012cff548e3fa064a4e2baace154c0 Mon Sep 17 00:00:00 2001 From: Jeremy Hughes Date: Fri, 24 Jul 2009 18:24:46 +1200 Subject: [PATCH 3/4] alien.marshall: docs lint fix --- extra/alien/marshall/marshall-docs.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/alien/marshall/marshall-docs.factor b/extra/alien/marshall/marshall-docs.factor index deac9fd186..7b321bd992 100644 --- a/extra/alien/marshall/marshall-docs.factor +++ b/extra/alien/marshall/marshall-docs.factor @@ -330,7 +330,7 @@ HELP: out-arg-unmarshaller HELP: class-unmarshaller { $values { "type" " a C type string" } - { "quot" quotation } + { "quot/f" quotation } } { $description "If in the vocab in which this word is called, there is a subclass of " { $link alien-wrapper } " named after the type argument, " { $snippet "pointer-unmarshaller" } " will return a quotation which " @@ -376,7 +376,7 @@ HELP: struct-primitive-unmarshaller HELP: struct-unmarshaller { $values { "type" "a C type string" } - { "quot" quotation } + { "quot/f" quotation } } { $description "Returns a quotation which wraps its argument in the subclass of " { $link struct-wrapper } " which matches the " { $snippet "type" } " arg." From 5336d717500b8f2817df6a547dea8cf24cc08c41 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 24 Jul 2009 18:05:23 -0500 Subject: [PATCH 4/4] sequences: update docs a bit --- core/sequences/sequences-docs.factor | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 0a301b3e38..9277a04b6e 100755 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -627,7 +627,7 @@ HELP: slice-error } ; HELP: slice -{ $class-description "A virtual sequence which presents a subrange of the elements of an underlying sequence. New instances can be created by calling " { $link } "." +{ $class-description "A virtual sequence which presents a subrange of the elements of an underlying sequence. New instances can be created by calling " { $link } ". Convenience words are also provided for creating slices where one endpoint is the start or end of the sequence; see " { $link "sequences-slices" } " for a list." $nl "Slices are mutable if the underlying sequence is mutable, and mutating a slice changes the underlying sequence. However, slices cannot be resized after creation." } ; @@ -1357,7 +1357,15 @@ ARTICLE: "virtual-sequences-protocol" "Virtual sequence protocol" { $subsection virtual@ } ; ARTICLE: "virtual-sequences" "Virtual sequences" -"Virtual sequences allow different ways of accessing a sequence without having to create a new sequence or a new data structure altogether. To do this, they translate the virtual index into a normal index into an underlying sequence using the " { $link "virtual-sequences-protocol" } "." +"A virtual sequence is an implementation of the " { $link "sequence-protocol" } " which does not store its own elements, and instead computes them, either from scratch or by retrieving them from another sequence." +$nl +"Implementations include the following:" +{ $list + { $link reversed } + { $link slice } + { $link iota } +} +"Virtual sequences can be implemented with the " { $link "virtual-sequences-protocol" } ", by translating an index in the virtual sequence into an index in another sequence:" { $subsection "virtual-sequences-protocol" } ; ARTICLE: "sequences-integers" "Counted loops" @@ -1422,6 +1430,16 @@ ARTICLE: "sequences-appending" "Appending sequences" { $subsection pad-tail } ; ARTICLE: "sequences-slices" "Subsequences and slices" +"There are two ways to extract a subrange of elements from a sequence. The first approach creates a new sequence of the same type as the input, which does not share storage with the underlying sequence. This takes time proportional to the number of elements being extracted. The second approach creates a " { $emphasis "slice" } ", which is a virtual sequence (see " { $link "virtual-sequences" } ") sharing storage with the original sequence. Slices are constructed in constant time." +$nl +"Some general guidelines for choosing between the two approaches:" +{ $list + "If you are using mutable state, the choice has to be made one way or another because of semantics; mutating a slice will change the underlying sequence." + { "Using a slice can improve algorithmic complexity. For example, if each iteration of a loop decomposes a sequence using " { $link first } " and " { $link rest } ", then the loop will run in quadratic time, relative to the length of the sequence. Using " { $link rest-slice } " changes the loop to run in linear time, since " { $link rest-slice } " does not copy any elements. Taking a slice of a slice will “collapse” the slice so to avoid the double indirection, so it is safe to use slices in recursive code." } + "Accessing elements from a concrete sequence (such as a string or an array) is often faster than accessing elements from a slice, because slice access entails additional indirection. However, in some cases, if the slice is immediately consumed by an iteration combinator, the compiler can eliminate the slice allocation and indirect altogether." + "If the slice outlives the original sequence, the original sequence will still remain in memory, since the slice will reference it. This can increase memory consumption unnecessarily." +} +{ $heading "Subsequence operations" } "Extracting a subsequence:" { $subsection subseq } { $subsection head } @@ -1436,7 +1454,8 @@ ARTICLE: "sequences-slices" "Subsequences and slices" { $subsection unclip-last } { $subsection cut } { $subsection cut* } -"A " { $emphasis "slice" } " is a virtual sequence which presents as view of a subsequence of an underlying sequence:" +{ $heading "Slice operations" } +"The slice data type:" { $subsection slice } { $subsection slice? } "Extracting a slice:"