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

World: r3wp

[Core] Discuss core issues

Maxim
28-Oct-2010
[208]
sorry  [1 2 3 2 3 4]
GrahamC
28-Oct-2010
[209]
well, that's no good is it!
Maxim
28-Oct-2010
[210]
so you want to remove singletons from a block?
GrahamC
28-Oct-2010
[211x2]
yes .. so why isn't alter doing that?
actually I want to remove one of each
Maxim
28-Oct-2010
[213]
ok so given:    [ 1 2 3 1 2 3 1 4 ] 
what is desired result?
GrahamC
28-Oct-2010
[214x3]
[ 1 2 3 ]
maybe I do want exclude and then unqiue
no .. exclude operates on sets
Maxim
28-Oct-2010
[217]
if you know [4] then that will work

blk:  [ 1 2 3 1 2 3 1 4 ]
unique exclude blk [4]
GrahamC
28-Oct-2010
[218]
I don't know
Maxim
28-Oct-2010
[219]
ok working on a solution (I like these quick riddles)
GrahamC
28-Oct-2010
[220x3]
I'm going to have to use a loop :(
I don't know why subtract does not work on blocks
foreach el set2 [ remove find set1 el ]
Maxim
28-Oct-2010
[223]
I tried yours and it didn't seem to work... but this definitely does:

c: 0
blk:  [ 1 2 3 1 2 3 1 4 ]

unique remove-each i copy blk [ c: c + 1 not find (at blk c + 1) 
i]
GrahamC
28-Oct-2010
[224x2]
I can't see why mine won't work ...
since set2 is a unique version of set1, it will always find and always 
remove
Carl
28-Oct-2010
[226]
I've long considered + and - on blocks to be useful... but, would 
others agree?
Maxim
28-Oct-2010
[227]
YES!
GrahamC
28-Oct-2010
[228x2]
go for it!
though I don't mind if we use 'subtract and 'add
Carl
28-Oct-2010
[230]
They're the same.
Maxim
28-Oct-2010
[231x2]
there is also a really usefull missing "set" function


duplicates:   returns items in a series present multiple times in 
that series.


without this function, right now there are many missing combinations.
to get singletons:

exclude blk duplicates block
GrahamC
28-Oct-2010
[233]
next you'll be asking for the ability to create combinations and 
permutations!
Maxim
28-Oct-2010
[234]
well, AFAIK duplicates is probably the single most frequently re-requested 
series function I've seen in the years.
GrahamC
28-Oct-2010
[235]
so return those in a block where there exists more than one?
Maxim
28-Oct-2010
[236]
yep.
GrahamC
28-Oct-2010
[237x2]
which is essentially what I was trying to do above
what instances have you needed this?
Maxim
28-Oct-2010
[239x2]
but its so usefull in simplifying many other loops and algorithms.
when managing data sets, you often want to know what is unique "within" 
that set.   

duplicates and singletons are often-required things you want to know 
about a data set.
GrahamC
28-Oct-2010
[241]
i guess make a wish on curecode for R3
Maxim
28-Oct-2010
[242x2]
yes... I just thought about that.
I will.
GrahamC
29-Oct-2010
[244x3]
Has anyone a simple algorithm for calculating the last day of a month? 
 Or is a lookup table easiest?


get-end-month: func [ d [date!] /local tmp ][ tmp: d while [ tmp/month 
= d/month ][ tmp: tmp + 1 ] tmp ]
get-end-month: func [ d [date!] /local tmp ][ tmp: d while [ tmp/month 
= d/month ][ tmp: tmp + 1 ] tmp - 1 ]
get-end-month: func [ d [date!] /local tmp ][ tmp: d  tmp/day: 28 
while [ tmp/month = d/month ][ tmp: tmp + 1 ] tmp - 1 ]
Gregg
29-Oct-2010
[247]
set 'last-day-of-month func [date /local d] [
    d: date
    d/day: 1
    d/month: d/month + 1
    d: d - 1
    d
]
GrahamC
29-Oct-2010
[248]
nice
Henrik
30-Oct-2010
[249]
>> append [] 'now/precise
== [now precise]

is there a better way?
Sunanda
30-Oct-2010
[250]
Is this better? To get an unevaluated now/precise into a block:
    append [] [now/precise]
Henrik
30-Oct-2010
[251x3]
possibly...
found a different way, so won't be needed.
I wanted a nice way to produce fragmented message strings that will 
be translated later, using a TRANSLATE function. So I made this function:

tell: func [blk /local out s] [
	out: make string! 10000
	parse blk [
		any [
			[
				set s string! (append out translate s)

    | to any-type! copy code [to string! | to end] (append out to string! 
    reduce [#"'" mold/only do code #"'"])
			]
			(append out #" ")
		]
	]
	join trim out #"."
]

>> file: what-dir
== %/c/program files/rebol/view/

>> tell ["File" file "cannot be found"]
== {File '%/c/program files/rebol/view/' cannot be found.}
Ladislav
30-Oct-2010
[254]
>> append/only [] 'now/precise
== [now/precise]
Henrik
30-Oct-2010
[255]
interesting, thanks
Gabriele
31-Oct-2010
[256]
Henrik, I don't think that's nice, because you can't really translate 
"File" and "cannot be found" separately. Don't expect all languages 
to have the same grammar structure etc.
Henrik
31-Oct-2010
[257]
Gabriele, probably not, but the language system, I'm working with 
works like this.