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

World: r3wp

[I'm new] Ask any question, and a helpful person will try to answer.

Henrik
27-Nov-2008
[1594]
Since you are new to programming:


Beginning with an existing program like this may not be optimal for 
understanding how things work, because there are tens of things going 
on in that example. It's the understanding of the underlying principles 
that allow you to build your own programs, and beginning with a big 
example like this throws all principles in your face at once. That 
can be very confusing, like being asked to fly a jumbo jet without 
training. This is why it's so difficult for you to get this example 
to work.


What I would do: Put the program away for now and start using the 
console intensively. Write single commands or a single line of code. 
The immediate feedback from the console lets you learn quickly. The 
console is not simply a service to let you run programs: It's a powerful 
tool that allows you to LEARN. I use it every time I'm in doubt over 
what a specific command will do. The console is your friend. Don't 
be afraid of it. :-)


When you've written enough VID programs in the console, you can start 
looking at the example again, or even better: Write it from scratch 
yourself. That's the best approach.
Janko
8-Jan-2009
[1595x10]
I am havng some problem that I can't and can't understand or even 
recreate:
sample-tests2: copy [
	[ 	n "hello true"
		f [ 1 == 1	 ]
		r true
	]
	[ 	n "hello not false"
		f [ not false ]
		r true
	]
]


unit-test: func [ tests ] [ 
	foreach test tests [ 

  prin rejoin [ "===================" newline "TEST " test/n ": " ]
		print (do test/f)
		print test/r
		print (  equal? (do test/f) test/r )
		print if/else ( (do test/f) == test/r ) [ 
			" passed"	
		] [

   rejoin [ " **FAILED**" newline " expected: " mold test/r " | got: 
   " mold do test/f ]   
		]
		print ""
	]
]
I run: unit-test sample-tests2 and get
===================
TEST hello true: true
true
false
 **FAILED**
 expected: true | got: true

===================
TEST hello not false: true
true
false
 **FAILED**
 expected: true | got: true
those aditional prints are there for debugging, bot values are true 
(and before I had same problem with false) but the ( equal? ... ) 
is false .. I tried with == too
if I try anything similar in console like >> ( (do [ 1 == 1 ] ) == 
true )
== true
>> ( equal? (do [ 1 == 1 ] ) true )
== true
>> ( equal? (do [ not false ] ) true )
== true
>> ( equal? (do [ true ] ) true )
== true
I get true, but I get false in all these cases using the unit-test 
function
even the sample sample-tests3: copy [
	[ 	n "true test"
		f [ true ]
		r true	]
]
fails:
>> unit-test sample-tests3
===================
TEST true test: true
true
false
 **FAILED**
 expected: true | got: true
Sunanda
8-Jan-2009
[1605]
Difference is between 
  true --  a logic value
  'true --  a word.

Try this:

sample-tests2: copy compose/deep[
	 [ 	n "hello true"
		f [ 1 == 1	 ]
		r (true)
	]
	[ 	n "hello not false"
		f [ not (false) ]
		r (true)
	]
]
Janko
8-Jan-2009
[1606x2]
I have been looking into this for for more than an hour
hi, Sunanda.. I will try
Sunanda
8-Jan-2009
[1608]
That forces the string t.r.u.e. into being a logic value, not the 
word 'true
Janko
8-Jan-2009
[1609]
hm.. now it works!!
Maxim
8-Jan-2009
[1610]
words are complicated things in rebol, they are symbols, variables 
and litterals... the problem is that two of those forms share the 
same lexical syntax.  :-(
Sunanda
8-Jan-2009
[1611]
The root problem is here:
true = [true]
Janko
8-Jan-2009
[1612]
so the problem is that if I write [ true ] inro block and that doesn't 
get reduced/evaluated it's a word not a logic value?
Sunanda
8-Jan-2009
[1613x2]
Sorry, I meant:
  true = first [true]
Compare with
  true = first reduce [true]
xavier
8-Jan-2009
[1615]
what kind of tool are you using ? a unit test framework ? Can you 
give me the reference ?
Sunanda
8-Jan-2009
[1616]
Then  use compose/deep as a way of effecting a reduce/deep which 
is what you need.
Janko
8-Jan-2009
[1617]
aha, now I get it >> do [ true ] == first [ true ]
== false
Sunanda
8-Jan-2009
[1618]
That's it!
It's a subtle REBOL gotcha.
Janko
8-Jan-2009
[1619x2]
thanks for this, I was banging my head for more than an hour...
:) well at least now I know somethinh more
Maxim
8-Jan-2009
[1621]
janko, you are now officially starting to be an advanced rebol user 
 ;-)   congratulations  :-)
xavier
8-Jan-2009
[1622x3]
there is a tool called runit ... designed by a guy i know, if you 
can get it maybe it can help
run
not runit sorry
Janko
8-Jan-2009
[1625]
Maxim : wow, then this hour was totally worth it ;)
Sunanda
8-Jan-2009
[1626]
Several of us have mortar dust in our hair from such issues :-)


Run unit is available here: (Peter Wood is an expert in using it):
http://www.rebol.org/view-script.r?script=run.r
Janko
8-Jan-2009
[1627]
xavier, Sunanda: thanks I will look at it... I need just simple unit 
testing for now , but I will look at it to see what a bigger solution 
might be
xavier
8-Jan-2009
[1628]
its very easy to use :) and quite powerfull
Janko
8-Jan-2009
[1629]
is there any simple example of use somewhere?
xavier
8-Jan-2009
[1630x2]
i still have some sample on my laptop
i send them to you
Sunanda
8-Jan-2009
[1632]
The documentation has some lengthy examples:
  http://www.rebol.org/documentation.r?script=run.r
Janko
8-Jan-2009
[1633x3]
aha cool
thanks
about word / value .. I see I there are functions word? value? which 
determine the difference between true-s
Sunanda
8-Jan-2009
[1636]
You mean like:
   word? true
   == false
   word? 'true 
   == true
Or:
   type? true
   ==logic!
   type? 'true
   == word!
xavier
8-Jan-2009
[1637]
in the first case true is a value and in the second case true is 
a litteral
Steeve
8-Jan-2009
[1638]
Janko, you can avoid the reduce/compose by using this syntax
>> true = first [true]
== false
>> true = first [#[true]]
== true
Janko
8-Jan-2009
[1639x3]
I changed the function to this so I can have testcases structure 
as it was initially
unit-test: func [ tests ] [ 
	foreach test tests [ 

  prin rejoin [ "===================" newline "TEST " test/n ": " ]
		res: if/else word? test/r [ do test/r ] [ test/r ]
		print if/else ( (do test/f) == res ) [ 
			" passed"	
		] [

   rejoin [ " **FAILED**" newline " expected: " mold test/r " | got: 
   " mold do test/f ]   
		]
		print ""
	]
]
I added the line :: res: if/else word? test/r [ do test/r ] [ test/r 
]
Steeve
8-Jan-2009
[1642]
we prefer to use EITHER instead of IF/ELSE
Janko
8-Jan-2009
[1643]
aha, I would like it better to.. if/else is gard to read.. but I 
didn't know it exists :)