From 91d638450d32af36195884b2fe345fbfe62b77fa Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 19 Jul 2005 08:23:33 +0000 Subject: [PATCH] string-compare ==> lexi, string> ==> lexi> --- CHANGES.txt | 6 ++- TODO.FACTOR.txt | 3 +- library/bootstrap/primitives.factor | 1 - library/collections/sequence-eq.factor | 8 ++++ library/collections/sequences-epilogue.factor | 23 +++++++++++ library/collections/strings-epilogue.factor | 6 +-- library/collections/strings.factor | 18 +-------- library/collections/vectors-epilogue.factor | 12 ++---- library/httpd/browser-responder.factor | 2 +- library/io/files.factor | 2 +- library/test/lists/combinators.factor | 2 +- library/test/strings.factor | 4 +- library/test/words.factor | 16 ++++++++ library/tools/inspector.factor | 3 -- library/tools/memory.factor | 10 +---- library/ui/books.factor | 4 +- library/ui/borders.factor | 4 +- library/ui/editors.factor | 6 +-- library/ui/frames.factor | 2 +- library/ui/gadgets.factor | 6 +-- library/ui/gestures.factor | 4 +- library/ui/hand.factor | 12 +++--- library/ui/hierarchy.factor | 5 ++- library/ui/incremental.factor | 10 +++-- library/ui/init-world.factor | 6 ++- library/ui/layouts.factor | 8 ++-- library/ui/menus.factor | 2 +- library/ui/paint.factor | 4 +- library/ui/scrolling.factor | 10 ++--- library/ui/shapes.factor | 38 +++++-------------- library/ui/splitters.factor | 6 +-- library/ui/tutorial.factor | 3 +- library/ui/ui.factor | 2 +- library/vocabularies.factor | 14 +++++-- library/words.factor | 2 +- native/debug.c | 20 ++++++++++ native/primitives.c | 1 - native/string.c | 28 -------------- native/string.h | 2 - 39 files changed, 157 insertions(+), 158 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 50fa49453a..d49954aba2 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -27,7 +27,11 @@ Factor 0.76: [ "Hello" % " world" % ] make-string Now, the former raises a type error. - + +- The string-compare primitive has been replaced with the lexi word + which now operates on any pair of sequences of numbers. The + string> word has been replaced with lexi>. + - The stream-write, stream-write-attr, write and write-attr generic words no longer accept a character as an argument. Use the new stream-write1 and write1 generic words to write single characters. diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 718d764fac..1c1425ee3b 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -7,12 +7,11 @@ - rollovers broken with menus - menu dragging - fix up the min thumb size hack -- bevel borders - nicer scrollbars with up/down buttons - gaps in pack layout - fix listener prompt display after presentation commands invoked - stack display bugs -- simple tutorial +- tutorial: clickable code snippets - parser::skip clean up + misc diff --git a/library/bootstrap/primitives.factor b/library/bootstrap/primitives.factor index 9834480f5e..a73264b410 100644 --- a/library/bootstrap/primitives.factor +++ b/library/bootstrap/primitives.factor @@ -44,7 +44,6 @@ vocabularies get [ [ "dispatch" "kernel-internals" [ [ fixnum vector ] [ ] ] ] [ "cons" "lists" [ [ object object ] [ cons ] ] ] [ "" "vectors" [ [ integer ] [ vector ] ] ] - [ "string-compare" "strings" [ [ string string ] [ integer ] ] ] [ "rehash-string" "strings" [ [ string ] [ ] ] ] [ "" "strings" [ [ integer ] [ sbuf ] ] ] [ "sbuf>string" "strings" [ [ sbuf ] [ string ] ] ] diff --git a/library/collections/sequence-eq.factor b/library/collections/sequence-eq.factor index cc132010d1..049c2e6cdc 100644 --- a/library/collections/sequence-eq.factor +++ b/library/collections/sequence-eq.factor @@ -31,3 +31,11 @@ M: sequence = ( obj seq -- ? ) ] [ over type over type eq? [ sequence= ] [ 2drop f ] ifte ] ifte ; + +M: string = ( obj str -- ? ) + over string? [ + over hashcode over hashcode number= + [ sequence= ] [ 2drop f ] ifte + ] [ + 2drop f + ] ifte ; diff --git a/library/collections/sequences-epilogue.factor b/library/collections/sequences-epilogue.factor index 86f352d1e7..843f6fea03 100644 --- a/library/collections/sequences-epilogue.factor +++ b/library/collections/sequences-epilogue.factor @@ -211,6 +211,29 @@ M: object reverse ( seq -- seq ) [ ] keep like ; #! Is every element of seq1 in seq2 swap [ swap member? ] all-with? ; +! Lexicographic comparison +: (lexi) ( seq seq i limit -- n ) + 2dup >= [ + 2drop swap length swap length - + ] [ + >r 3dup 2nth 2dup = [ + 2drop 1 + r> (lexi) + ] [ + r> drop - >r 3drop r> + ] ifte + ] ifte ; + +: lexi ( s1 s2 -- n ) + #! Lexicographically compare two sequences of numbers + #! (usually strings). Negative if s1s2. + 0 pick length pick length min (lexi) ; + +: lexi> ( seq seq -- ? ) + #! Test if the first sequence follows the second + #! lexicographically. + lexi 0 > ; + IN: kernel : depth ( -- n ) diff --git a/library/collections/strings-epilogue.factor b/library/collections/strings-epilogue.factor index 4bb36a4e35..35d0ee0f5a 100644 --- a/library/collections/strings-epilogue.factor +++ b/library/collections/strings-epilogue.factor @@ -4,8 +4,7 @@ IN: strings USING: generic kernel kernel-internals lists math namespaces sequences strings ; -: empty-sbuf ( len -- sbuf ) - dup [ set-length ] keep ; +: empty-sbuf ( len -- sbuf ) dup [ set-length ] keep ; : fill ( count char -- string ) >string ; @@ -28,7 +27,6 @@ M: string thaw >sbuf ; M: string like ( seq sbuf -- string ) drop >string ; -M: sbuf clone ( sbuf -- sbuf ) - [ length dup ] keep nappend ; +M: sbuf clone ( sbuf -- sbuf ) >sbuf ; M: sbuf like ( seq sbuf -- sbuf ) drop >sbuf ; diff --git a/library/collections/strings.factor b/library/collections/strings.factor index e1d23fb8f4..871f2e6fe8 100644 --- a/library/collections/strings.factor +++ b/library/collections/strings.factor @@ -7,28 +7,12 @@ USING: generic kernel kernel-internals lists math sequences ; DEFER: string? BUILTIN: string 12 string? [ 1 length f ] [ 2 hashcode f ] ; -M: string = - over string? [ - over hashcode over hashcode number= [ - string-compare 0 eq? - ] [ - 2drop f - ] ifte - ] [ - 2drop f - ] ifte ; - -M: string nth ( n str -- ch ) - bounds-check char-slot ; +M: string nth ( n str -- ch ) bounds-check char-slot ; GENERIC: >string ( seq -- string ) M: string >string ; -: string> ( str1 str2 -- ? ) - ! Returns if the first string lexicographically follows str2 - string-compare 0 > ; - ! Characters PREDICATE: integer blank " \t\n\r" member? ; PREDICATE: integer letter CHAR: a CHAR: z between? ; diff --git a/library/collections/vectors-epilogue.factor b/library/collections/vectors-epilogue.factor index b1f7a72c18..9fdcd677e4 100644 --- a/library/collections/vectors-epilogue.factor +++ b/library/collections/vectors-epilogue.factor @@ -5,22 +5,16 @@ math-internals sequences ; IN: vectors -: empty-vector ( len -- vec ) - #! Creates a vector with 'len' elements set to f. Unlike - #! , which gives an empty vector with a certain - #! capacity. - dup [ set-length ] keep ; +: empty-vector ( len -- vec ) dup [ set-length ] keep ; : >vector ( list -- vector ) dup length [ swap nappend ] keep ; M: repeated thaw >vector ; -M: vector clone ( vector -- vector ) - >vector ; +M: vector clone ( vector -- vector ) >vector ; -: zero-vector ( n -- vector ) - 0 >vector ; +: zero-vector ( n -- vector ) 0 >vector ; M: general-list thaw >vector ; diff --git a/library/httpd/browser-responder.factor b/library/httpd/browser-responder.factor index a8e65854e4..f6807faf9b 100644 --- a/library/httpd/browser-responder.factor +++ b/library/httpd/browser-responder.factor @@ -57,7 +57,7 @@ sequences ; #! Write out the HTML for the list of words in a vocabulary.