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

World: r3wp

[Core] Discuss core issues

GrahamC
28-Oct-2010
[196]
someop [ 1 1 2 3 4 ] [ 1 ] 
== [ 1 2 3 4 ]
Maxim
28-Oct-2010
[197]
exclude
GrahamC
28-Oct-2010
[198]
oh .. it's alter
Maxim
28-Oct-2010
[199]
but it will add them if they're not there.
GrahamC
28-Oct-2010
[200x2]
that's okay ... I need to remove all elements where there's only 
one of them
all patients who have had more than one office visit over the past 
year with a diagnosis of hypertension :)
Maxim
28-Oct-2010
[202x2]
oh ... you want  'UNIQUE
why do you need the second argument?

unique [ 1 1 2 3 4 ]
== [ 1 2 3 4 ]
GrahamC
28-Oct-2010
[204]
no .. I want alter

set1: [ 1 2 3 1 2 3 4 ] <= need to remove 4
set2: unique copy set1
alter set1 set2
Maxim
28-Oct-2010
[205]
no need for copy... all "set" functions copy.
GrahamC
28-Oct-2010
[206]
can never remember which copy and which inline
Maxim
28-Oct-2010
[207x2]
the above returns...  [1 2 3 4] on my test.
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
[244x2]
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 ]