r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Anton
27-Oct-2008
[11208]
>> cut: func [ w n ][ set w copy/part get w n]
>> o: context [s: "hello"]
>> cut in o 's 3
== "hel"
>> o/s
== "hel"
>> t: "bonjour"
== "bonjour"
>> cut 't 3
== "bon"
Graham
27-Oct-2008
[11209]
Ok
Anton
27-Oct-2008
[11210x4]
Navigating my public directory:
>> change-dir %"~niclasen/"
** Access Error: Bad file path: ~niclasen/
** Where: clean-path
** Near: get-modes target 'full-path
The ~niclasen directory was created automatically by path-thru (via 
load-thru).
CLEAN-PATH doesn't like the leading tilde '~'.
It's not in RAMBO.

R3 doesn't have this problem, but it seems that clean-path doesn't 
do anything with tildes. (Maybe R3 clean-path is not using the operating 
system to do path expansion.)
ChristianE
27-Oct-2008
[11214]
If by working in situ you mean you'd like to modify the series directly 
instead of copying parts of it, maybe you can use

cut-left: func [series length] [clear skip series length series]
cut-right: func [series length] [remove/part series length]

cut-middle: func [series start length] [cut-right series start - 
1 cut-left series length]
BrianH
27-Oct-2008
[11215]
Anton, the R3 clean-path is a mezzanine which only applies REBOL 
expansion rules, not OS-specific ones.
Anton
27-Oct-2008
[11216]
Aha, I see, clean-path is a much longer function, now that it's not 
using get-modes.
BrianH
27-Oct-2008
[11217x4]
Tilde expansion could be added using system/options/home if you like.
~ is a valid character for filenames on some platforms though.
Graham, try TAKE for your cut function.
Never mind, TAKE is the opposite of what you want. Try this:
cut: func [s [series!] n [number!]] [clear skip s max 0 n  s]
Gregg
27-Oct-2008
[11221]
'Cut doesn't seem like a good name for this. 'Cut is a *nix command 
that lets you "cut out" the columns you want from data. And if you 
say "cut ["Gregg Irwin" 5], does that mean to cut five chars or keep 
them, and from which end? I think 'keep is a better word for this, 
or maybe 'cut-to.


BTW, I have the same naming issue with my PAD func. i.e. does pad/right 
mean pad *to* the right, or *on* the right. Sometimes you just have 
to live with a bit of ambiguity.
BrianH
27-Oct-2008
[11222]
KEEP is used elsewhere. This is more of a constraint. Perhaps cut-length 
or something like that.
Graham
27-Oct-2008
[11223]
Trim is also taken
Anton
27-Oct-2008
[11224]
BrianH, I actually didn't want tilde expansion for that case (an 
actual directory in the public cache), so R3's behaviour would have 
been good for me. Just wondering if anyone has any thoughts about 
the issue in R2.
Gregg
28-Oct-2008
[11225]
Where is KEEP used? Under R3 it may still be in the COLLECT spec, 
but I don't recall it in R2.
Anton
28-Oct-2008
[11226]
What about FIT ?
Graham
28-Oct-2008
[11227]
I was also thinking of fit
DideC
28-Oct-2008
[11228]
clear-at
Anton
28-Oct-2008
[11229]
discard
BrianH
28-Oct-2008
[11230x2]
COLLECT will be back-ported to R2. At the time of the 2.7.6 release 
the function was still under discussion - now it is finalized. We 
only backport final functions. I'm thinking that FOLD will probably 
make it too :)
How about TRIM-LENGTH ?
btiffin
28-Oct-2008
[11232]
Graham;  'only  'lop 'betail  'amputate  'pare  ''shorten  ''abscind 
     load up the dict protocol demo and >> thes truncate for more
Anton
28-Oct-2008
[11233]
oohoo, truncate's good.
BrianH
29-Oct-2008
[11234]
I like truncate.
btiffin
29-Oct-2008
[11235]
And just to place credit where it belongs ... Our good Chris was 
first with truncate   ... I was simply using it as a good launch 
point for a thesaurus scan.
Graham
29-Oct-2008
[11236x2]
how about 'lose
never seen that word used in a REBOL script!  :)
Anton
30-Oct-2008
[11238]
'lop is pretty good, because it (probably) implies a fixed length. 
eg. a forester might lop the tops off some trees.
Tomc
30-Oct-2008
[11239x2]
how about  trim/integer  ?  example

abbrev:  trim/3 month
trim/-n  could keep the last n chars
BrianH
30-Oct-2008
[11241]
Tom, that wouldn't work with REBOL's evaluation rules. Native or 
not, you can't write a function that way.
Tomc
30-Oct-2008
[11242]
picky  picky    
mth:  trim/lenght  month 3
Henrik
31-Oct-2008
[11243]
trim/to perhaps
Graham
31-Oct-2008
[11244]
Cut
Keep
Fit
Clear-at
Constrain

Discard
Trim-length
Truncate
Lose
Lop
Trim/to
Henrik
31-Oct-2008
[11245]
In this sense, CUT would mean split in two parts, I think. TRUNCATE 
is accurate, but TRIM/TO is a little shorter.
DideC
31-Oct-2008
[11246]
clear-at (its what it does)
truncate (its what it seems to do)
Graham
31-Oct-2008
[11247]
in that case, I would use trunc :)
Graham
5-Nov-2008
[11248x2]
One thing I do is to remove the outer characters eg. "[Something]" 
=> "Something"
Python has good tools for dealing with these functions.
Chris
5-Nov-2008
[11250]
That's where a range! datatype would come in handy:

copy/part "[Something]" 1..-1
Graham
5-Nov-2008
[11251x2]
Yep
this is Gregg's substr function


substring: func [
    [catch]
    source [string!]
    spec [block!]
    /local start stop rule
][
    rule: [set start integer! '.. set stop integer!]
    unless parse spec rule [
        throw make error! "Invalid range spec."
    ]
    copy/part skip source start stop
]
Chris
5-Nov-2008
[11253]
You could produce a 'truncate function that uses a pair! to similar 
effect...

truncate: func [string limit [pair! integer!]][
	if integer? limit [limit: 1x0 * limit]
	string: copy string
	case [
		negative? limit/x [remove/part string skip tail string limit/x]
		positive? limit/x [remove/part string limit/x]
		negative? limit/y [clear skip tail string limit/y]
		positive? limit/x [clear skip string limit/y]
	]
	string
]
Graham
5-Nov-2008
[11254x2]
the ".." is syntactic sugar.
the dialect doesn't cope with negative offsets it seems
Chris
5-Nov-2008
[11256x2]
; This works!:

truncate: func [string limit [pair! integer!]][
	if integer? limit [limit: 1x0 * limit]
	string: copy string
	case/all [
		negative? limit/x [limit/x: limit/x + length? string]
		negative? limit/y [limit/y: limit/y + length? string]
	]
	clear skip string limit/y
	remove/part string limit/x
]
>> truncate "[abc]" 1x-1 
== "abc"