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

World: r3wp

[Core] Discuss core issues

Ladislav
10-Feb-2007
[7066x2]
...check each value in the block for safety?
 - no
just the first one
Graham
10-Feb-2007
[7068x2]
Ok, I'm going to use this example first : 0.56 * sqrt(tender28) + 
0.28 * sqrt(swollen28) + 0.70 * ln(ESR) + 0.014 * GH
turn that into Rebol first ... and then only check the first value?
Ladislav
10-Feb-2007
[7070]
it looks, like you want to use any expression, not just function 
evaluation?
Graham
10-Feb-2007
[7071]
yes ..
Ladislav
10-Feb-2007
[7072]
then it is not for you, this was just for a function evaluation
Graham
10-Feb-2007
[7073]
Ok, so looks like it will have to be a parser
Ladislav
10-Feb-2007
[7074]
yes
Graham
10-Feb-2007
[7075]
but it would be nice to be able to use the rebol parser do evaluate 
words within a mathematical context only
Ladislav
10-Feb-2007
[7076]
when using a parser, you can even use operator precedence rules and 
such
Graham
10-Feb-2007
[7077x6]
A non parse based solution ( ie. parse = too hard! )
eval-math: func [ exp [string!]
	/local t allowed okay
][
	allowed: [ + - / square-root log-e * ]
	t: to block! exp
	bind t '+
	okay: true
	allowed: [ + - / square-root log-e * ]
	foreach e t [
		switch/default type?/word e [
			paren! [ eval-math form e ]
			word! [ if not find allowed e [ okay: false break ]]
			decimal! []
			integer! []
		][ okay: false break ]
	]
	either okay [
		do t
	][ none ]
]
Hmm.  Needs debugging
eval-math: func [ exp [string!]
	/local t allowed
][
	allowed: [ + - / square-root log-e * ]
	t: to block! exp
	bind t '+
	foreach e t [
		switch/default type?/word e [
			paren! [ if none? eval-math form e [ return none ]	]
			word! [ 
				if not find allowed e [ 
					print [ "not allowed is : " e ]
					return none
				]
			]
			decimal! []
			integer! []
		][ return none ]
	]
	do t
]
How does one access the parts of a function?
eg; func [face /local var][print face/text] 
how do I get to the [print face/text ] part?
Ladislav
10-Feb-2007
[7083]
second func [face /local var] [print face/text] ; == [print face/text]
Graham
10-Feb-2007
[7084x2]
oh?  and third is the locals ?
I was thinking it should be after third and not before :(
Ladislav
10-Feb-2007
[7086]
first is the simplified spec, third is the complete spec
Graham
10-Feb-2007
[7087]
ah ...
Ladislav
10-Feb-2007
[7088]
third was added later than first and second IIRC
Graham
10-Feb-2007
[7089x2]
What was pekr talking about regarding alpha r3 core release?
Do you know?
Ladislav
10-Feb-2007
[7091]
no
Graham
10-Feb-2007
[7092]
too much beer?
Ladislav
10-Feb-2007
[7093]
fiction writer, maybe
Graham
10-Feb-2007
[7094x2]
porkies ?
Seems I have enough clues now to write my little spreadsheet :)
Pekr
11-Feb-2007
[7096]
Graham - it was a joke. And I thought as maybe ppl would not understand, 
if I would post it in Announce group, I posted it rather in Humour 
group :-)
Gabriele
11-Feb-2007
[7097x2]
graham: why are you using to-block there? (my assumption is that 
you wanted to avoid the binding of load, but then you manually bind 
to the global context, so you can just use load)
a different approach is to create a context with only the words you 
want to allow, then use to-block, then bind it to your context only, 
then do it.
Ladislav
11-Feb-2007
[7099]
yes, the transformation to string and to block back and forth looks 
a bit messy
Volker
11-Feb-2007
[7100x3]
in-shadow-context: use first system/words['some-word]

then bind to 'some-word. somewhat  expensive, but you do it only 
on input. 

Escapes: it  does not go into #[object![..]]. I have  a function 
which does  that too.  ifthe user can do a  stringwith a new word, 
that  word is still global.
and  then fill your functions in.
use first system/words reduce[f1: (:f1) ... 'some-word]
no,  compose.
Ladislav
11-Feb-2007
[7103]
UNBIND might help handling such constructs, maybe
Volker
11-Feb-2007
[7104x2]
It would. do we have it?
I hope in  r3
Ladislav
11-Feb-2007
[7106]
yes, it has been offered for R3 in a blog
Graham
11-Feb-2007
[7107]
Yes, I want to bind it to a different context to be safe .. so exactly 
how do I create this different context for all the math stuff?
Gabriele
11-Feb-2007
[7108x2]
>> a: context compose [
[    (to set-word! '+) get in system/words '+
[    ]
>> a/+

** Script Error: + expected value1 argument of type: number pair 
char money date time tuple
** Near: a/+
(don't ask me why +: is not a valid set-word)
Ladislav
11-Feb-2007
[7110x2]
another option:


math-words: [+ - * / ** = == =? < <= > >= and or xor square-root 
negate]
math-words: use math-words reduce [math-words]
foreach word math-words [set word get in system word]
etc.
the last line should have been:

    foreach word math-words [set word get in system/words word]
Volker
11-Feb-2007
[7112]
yes. but keep in mind bind ignores functions and objects, so you 
must  recurse into them too.
Maxim
11-Feb-2007
[7113x3]
can anyone confirm that these two statements should return the same 
value for the same blk and val?

select blk val
second find blk val


as long as val does exist in blk.
does select reduce both args before selecting?
my god... REBOL is going nuts!  I have a situation where the above 
is not true...  and the select pairs are [aword an-object bword another-object]