2011/8/16 Mute clown <withnom...@gmail.com>: > Never used a mailing list before, got kinda pushed into using it since for > some reason i cant talk in IRC.
Maybe you need to register your nick? > I am trying to learn how to use factor, the whole stack oriented, > concatenative programming is alien to me. I am trying to implement Herons > Formula, to work out the area of a triangle: > Area = sqrt(s(s-a)(s-b)(s-c)) > s = a+b+c /2 > I've sort of worked out how to do s: > : dev2 ( d -- s ) 2 / ; > : sem ( a b c -- s ) + + dev2 ; > Problem 1: > IDK why the following doesn't work. > : sem ( a b c -- s ) dup + + dev2 ; why dup? that equals to `a b c c + + 2 /` so the stack effect is ( a b c -- a s ). Don't dup, let the word "eat" all the arguments. If you want to dup `a b c`, use 3dup. > Problem 2: > say i get the above problem fixed(use dup before calling the word) > I dont know how to proceed with the current stack: > -bottom of the stack- > a > b > c > s > -top of the stack- > i've tried various words to modify the top of the stack but, can't seem to > arrange it into a way so i can compute what i need. Either use tri@ (tri, tri* and tri@ do different things with 3 quotations/values) or create array from a, b, c using 3array. Here are my attempts to solve your problem with same stack configuration: USING: arrays kernel math math.functions sequences ; IN: heron : s ( a b c -- s ) + + 2.0 / ; : area ( a b c -- S ) 3dup s dup [ [ swap - ] curry tri@ ] dip * * * sqrt ; ! using array : ss ( abcseq -- s ) sum 2.0 / ; : area2 ( a b c -- S ) 3array dup ss [ 0 suffix ] dip [ swap - ] curry map product sqrt ; If you don't understand, break into tiniest bits and run those interactively in listener. Also, look up unknown words at docs.factorcode.org and experiment with them to understand. Feel free to ask for clarification. Also, this one can be solved wihtou too much shuffling but some equations are really pain and in that case, consider using lexical variables, http://docs.factorcode.org/content/article-locals-examples.html has nice example with quadratic roots. Regards Jakub ------------------------------------------------------------------------------ Get a FREE DOWNLOAD! and learn more about uberSVN rich system, user administration capabilities and model configuration. Take the hassle out of deploying and managing Subversion and the tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2 _______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk