Factor – A practical stack language
21–30 of 42 posts
Re: Factor – A practical stack language
#22I really love the power of Factor. It is probably the most powerful language I have ever come across. That being said, I think there needs to be a more interactive method where you can see things on the stack in real time as you are programming. I found myself not being able to focus on the problem I wanted to solve and instead was spending too much of my brainpower on remembering what was on the stack where. If you…
> I think the problem can be solved though if the development environment shows the stack at each point in time; that way the computer does the thinking instead of the programmer. If you're up for it I have some code that I wrote with this very idea in mind, in Factor. I'll put it on github later today and put the link here anyway. I agree with you 100%. If Factor were transparent that way and interactive that way (t…
I have plans to do something similar but in the browser in Javascript. Basically, build up the AST based on the commands that are issued against the stack. Then use the Mozilla Parser API to generate Javascript code.
Additionally, with the example arguments supplied you have test driven develop built right in. Not only do you get tests, but it helps you visualize things as you program.
Re: Factor – A practical stack language
#23Re: Factor – A practical stack language
#24It's entirely my own failing, but I just can't get the hang of postfix languages. Feels too much like coding in Yodaspeak.
Some short functions look so beautiful... but I have a hard time as stuff gets more complex. https://github.com/slavapestov/factor/blob/master/extra/anag... IMO this: MEMO: dict-words ( -- seq ) "/usr/share/dict/words" ascii file-lines [ >lower ] map ; is beautiful.
Re: Factor – A practical stack language
#25I wonder what makes them say this in the FAQ: "a flexible enough type system for concatenative languages has not yet been designed. However, Factor 2.0 may include optional static typing, if a suitable type system can be found." http://kittenlang.org/ gives the impression of having a fairly sensible static type system.
I think the problem is that you want some words with dynamic/value-dependent stack effects. It’s hard to intermingle static and dynamic typing well, and hard to bring the utility of dependent typing for enforcing program properties into the realm of properties that are actually useful to enforce while remaining usable.
Re: Factor – A practical stack language
#26Earlier quoted context omitted.
Some short functions look so beautiful... but I have a hard time as stuff gets more complex. https://github.com/slavapestov/factor/blob/master/extra/anag... IMO this: MEMO: dict-words ( -- seq ) "/usr/share/dict/words" ascii file-lines [ >lower ] map ; is beautiful.
I believe the same is true of other paradigms. Of course complexity is difficult. Do concatenative languages exaggerate the effect?
You define new words for the sole purpose of keeping things short and to the point. This holds true for most languages (At least if you want readable and maintainable code), but a language like Factor, this becomes an absolute necessity.
I would not be surprised if this is the reason Factor is called Factor. Specifically when related to factoring in Algebra where you do much the same thing: "splitting" an expression into a multiplication of simpler expressions.
Re: Factor – A practical stack language
#27Earlier quoted context omitted.
Some short functions look so beautiful... but I have a hard time as stuff gets more complex. https://github.com/slavapestov/factor/blob/master/extra/anag... IMO this: MEMO: dict-words ( -- seq ) "/usr/share/dict/words" ascii file-lines [ >lower ] map ; is beautiful.
I believe the same is true of other paradigms. Of course complexity is difficult. Do concatenative languages exaggerate the effect?
: ( -- gadget )
vertical
{ 5 5 } >>gap
[ f track-add ]
[
[ 1 track-add ]
[
[
vtruncate v>integer
first3 3dup "%d %d %d #%02x%02x%02x" sprintf
]
f track-add
] bi
] bi* ;Re: Factor – A practical stack language
#28I really love the power of Factor. It is probably the most powerful language I have ever come across. That being said, I think there needs to be a more interactive method where you can see things on the stack in real time as you are programming. I found myself not being able to focus on the problem I wanted to solve and instead was spending too much of my brainpower on remembering what was on the stack where. If you…
Joy is one of the major inspirations for Factor (I think it is considered the first "concatinative" language but I may be mistaken about that) and I think it deserves serious consideration from anyone interested in language design and formal systems. In a word, it's name is apt.
I have added a trace ability that lets the interpreter print out a complete description of the steps in an evaluation, like so (the bullet mark indicates the current interpreter "position", items to the left are on the stack, items to the right are the expression to be evaluated):
joy? 3 range_to_zero
# frame start
• 3 range_to_zero
3 • range_to_zero
# .. range_to_zero == unit [down_to_zero] infra
# .. frame start
3 • unit [down_to_zero] infra
# .... unit == [] cons
# .... frame start
3 • [] cons
3 [] • cons
[3] •
# .... frame end
# .... unit done.
[3] • [down_to_zero] infra
[3] [down_to_zero] • infra
# .... frame start
3 • down_to_zero
# ...... down_to_zero == [0 gt] [dup pred] while
# ...... frame start
3 • [0 gt] [dup pred] while
3 [0 gt] • [dup pred] while
3 [0 gt] [dup pred] • while
# ........ frame start
3 • 0 gt
3 0 • gt
True •
# ........ frame end
# ........ frame start
3 • dup pred
3 3 • pred
3 2 •
# ........ frame end
# ........ frame start
3 2 • 0 gt
3 2 0 • gt
3 True •
# ........ frame end
# ........ frame start
3 2 • dup pred
3 2 2 • pred
3 2 1 •
# ........ frame end
# ........ frame start
3 2 1 • 0 gt
3 2 1 0 • gt
3 2 True •
# ........ frame end
# ........ frame start
3 2 1 • dup pred
3 2 1 1 • pred
3 2 1 0 •
# ........ frame end
# ........ frame start
3 2 1 0 • 0 gt
3 2 1 0 0 • gt
3 2 1 False •
# ........ frame end
# ........ while done.
3 2 1 0 •
# ...... frame end
# ...... down_to_zero done.
3 2 1 0 •
# .... frame end
# .... infra done.
[0 1 2 3] •
# .. frame end
# .. range_to_zero done.
[0 1 2 3] •
# frame end
-> [0 1 2 3]
joy?
It's a little hard to follow but it is complete and visible.Re: Factor – A practical stack language
#29Earlier quoted context omitted.
I believe the same is true of other paradigms. Of course complexity is difficult. Do concatenative languages exaggerate the effect?
I think so sir - I had only a couple beers and can't parse the function below. : ( -- gadget ) vertical { 5 5 } >>gap [ f track-add ] [ [ 1 track-add ] [ [ vtruncate v>integer first3 3dup "%d %d %d #%02x%02x%02x" sprintf ] f track-add ] bi ] bi* ;
I can't parse it either, but I don't know if "readability for a beginner" is a metric I care a whole lot about in a programming language.
Re: Factor – A practical stack language
#30I've always wanted to learn a Lisp, but I've found Scheme too academic, so I ended up learning other variants such as Common Lisp and Clojure. Could the same thing be said about Factor vs Forth?