Paste: imaginary changes to factor lang :) - just experimenting

Author: middayc
Mode: factor
Date: Fri, 20 Nov 2009 02:06:51
Plain Text |
; started thinking about something like set-words get-words in factor (like rebol has)
; which enables you to steal (set) values from middle of flow (function pipeline) 
; in case you need to reuse it later
; :set-word  --- like "set-word" set now
; get-word:  --- like "get-word" get now
; :word -> #word --- so word definition has to change

; rebol example -- couldn't find any better at this time (you see I am using that r: in the middle of expression... 
; it sets r word and passes value forward
show-payment-history: func [ user /local R ] [
	html-table rejoin [ 
		html-table-row [ "Številka predračuna" "Številka računa" "Datum" "Mesecev" "Datum" "Znesek" "Plačano do" "Opombe" ] "th"
		either not empty? r: accumulate x acc copy "" (get-user-data-of "payments" user) [ 
				join acc html-table-row reduce [ x/order-id x/inv-id (get-plan-name x/plan) x/months x/when x/amount x/payed-to x/notes ] "td"
		] [ r ] [ wrap wrap "No payments yet." "td colspan='8'" "tr" ]
	]
]

;some very light stack manipulators.. 
#. drop ;
#.. drop drop ;
#* dup ;
#** dup dup ;
#^ swap ;   -- pull the second in stack to the front
#-^         -- pull the trird on the stant on the front
#--^
#.-
#.--

#email-data ( id :email. -- data ) 
    "http://www.data.com/" ^ append load 
        lines
            * first :title .
                rest [ ";" ^ split ] map <use array>
                    [ ** 2 pick ^ 5 pick average ^ 9 pick difference ] map 
                        >csv 
                            email: title: send-email ;


#sign-in ( user pwd -- userdata message )
    get-user-data :data null? 
        [ "try again" ] [ "welcome" data: name>> append ] either
            data: ^ ;
            
#add-item ( category-name name qty -- )
    --^ * get-category-id-by-name * null? 
        [ . add-category ] [ .- ] either
            add-item ;
    
#add-item ( category-name name qty -- )
    --^ * get-category-id-by-name :catid null? 
        [ add-category ] [ catid: ] either
            add-item ;
            
; simplistic style programming with (toomany) variables .. bad example I know
; var a = ..
; var b = ...
; return f(a,b);

#get-asda ( user month type -- report )
    ^ get-month-name :m-name .
    ^ get-user-data  :user-data .
    m-name: user-data: generate-report ;
    

Annotation: info

Author: Middayc
Mode: factor
Date: Fri, 20 Nov 2009 02:15:14
Plain Text |
in #email-data imagine you have file 
----
Some title of file
some;separated;values
some;separated;values
----

ok, I know csv to csv is lame.. I was just making things up

Annotation: easter

Author: erg
Mode: factor
Date: Fri, 20 Nov 2009 02:53:46
Plain Text |
:: easter-month-day ( year -- month day )
    year 19 mod :> a
    year 100 /mod :> ( b c )
    b 4 /mod :> ( d e )
    b 8 + 25 /i :> f
    b f - 1 + 3 /i :> g
    19 a * b + d - g - 15 + 30 mod :> h
    c 4 /mod :> ( i k )
    32 2 e * + 2 i * + h - k - 7 mod :> l
    a 11 h * + 22 l * + 451 /i :> m

    h l + 7 m * - 114 + 31 /mod 1 + :> ( month day )
    month day ;

Annotation: the imaginary lang code

Author: middayc
Mode: factor
Date: Fri, 20 Nov 2009 03:17:48
Plain Text |
: easter-month-day ( :year -- month day )
    year: 19 mod :a .
    year: 100 /mod :c :b .
    b: 4 /mod :e :d .
    b: 8 + 25 /i :f .
    b: f: - 1 + 3 /i :g .
    19 a: * b: + d: - g: - 15 + 30 mod :h .
    c: 4 /mod :k :i .
    32 2 e: * + 2 i: * + h: - k: - 7 mod :l .
    a: 11 h: * + 22 l: * + 451 /i :m .

    h: l: + 7 m: * - 114 + 31 /mod 1 + :day :month

Annotation: again

Author: middayc
Mode: factor
Date: Fri, 20 Nov 2009 03:23:42
Plain Text |
! forgot the dots
#easter-month-day ( :year -- month day )
    year: 19 mod :a .
    year: 100 /mod :c . :b .
    b: 4 /mod :e . :d .
    b: 8 + 25 /i :f .
    b: f: - 1 + 3 /i :g .
    19 a: * b: + d: - g: - 15 + 30 mod :h .
    c: 4 /mod :k :i .
    32 2 e: * + 2 i: * + h: - k: - 7 mod :l .
    a: 11 h: * + 22 l: * + 451 /i :m .

    h: l: + 7 m: * - 114 + 31 /mod 1 +

New Annotation

Summary:
Author:
Mode:
Body: