Re: [Factor-talk] The use and abuse of variables
On 12-Jan-07, at 2:43 AM, Eduardo Cavazos wrote: > On Friday 12 January 2007 01:03, Slava Pestov wrote: > >> If you want something closer to Scheme, you might want to investigate >> implementing lexically scoped variables, instead of extending the >> dynamically scoped namespace system from the core. > > Slava, I'd love to consider this, but can you give me a sketch of > how to > implement lexically scoped variables in Factor? Are you talking > about mucking > around in the core implementation? No, I think it may be possible as a library. I haven't thought about it much, perhaps you can play around. Slava - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On Friday 12 January 2007 01:03, Slava Pestov wrote: > If you want something closer to Scheme, you might want to investigate > implementing lexically scoped variables, instead of extending the > dynamically scoped namespace system from the core. Slava, I'd love to consider this, but can you give me a sketch of how to implement lexically scoped variables in Factor? Are you talking about mucking around in the core implementation? - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On 1/12/07, Eduardo Cavazos <[EMAIL PROTECTED]> wrote: > So let's get on with the use and abuse of Factor. :-D I played around with some similar ideas, but using pattern matching a couple of weeks ago. So words looked like: FOO: recurse ( h:t quot -- ) ?h:t empty? [ ?quot call bind ?t ?quot recurse ] unless ; FOO: my-subset3 ( seq quot result -- seq ) ?seq [ ?h ?quot call [ ?h ?result push ] when ] recurse ?result ?seq like ; FOO: would look at the stack effect of the word and perform a pattern match on the input stack against that stack effect. I also added list head/tail matching to the pattern matching library for this. So ?a:b would make ?a equal the head of the list and ?b the tail, and ?a:b the entire list. FOO: translated this: FOO: bar ( a b -- ) ?a ?b + ; To: : bar ( a b -- ) 2array { ?a ?b } match [ ?a ?b + ] bind ; I was exploring ideas on how to write combinator words at the time. I also hit the tail recursion problem. That problem being that calling itself from within a 'bind' is not tail recursive since 'bind' modifies the name stack after the call. Chris. -- http://www.bluishcoder.co.nz - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On 12-Jan-07, at 1:45 AM, Eduardo Cavazos wrote: > The reason I wanted to move away from symbols is that it's easy to > clash with > existing things like word names and tuple names. Clashing with > tuple names > hasn't caused a problem for me yet, but it seems weird. Then don't define words with the same name as variables :) If you want to do stuff like VAR: foo : foo ... ; Then have your >foo foo> words use wrappers, so that they read : >foo \ foo set ;. You might already be doing this, if you're calling [ set ] curry. If you want something closer to Scheme, you might want to investigate implementing lexically scoped variables, instead of extending the dynamically scoped namespace system from the core. Slava - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On Thursday 11 January 2007 21:52, Chris Double wrote: > > In the system I changed it so "foo" is used as the variable. > Isn't using a symbol the right thing though? Using a string means you > can get clashes with any other file that uses the same string name as > a variable. Maybe the thing to do is obfuscate the backend symbol just a little bit. So VAR: a might make the symbol _a for example. Or should I just go all out and gensym it? ;-) - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On Friday 12 January 2007 00:31, Slava Pestov wrote: > On 11-Jan-07, at 6:45 PM, Eduardo Cavazos wrote: > > : #foo ( -- ... ) ! Call the value of foo. E.g. "foo" get call > I don't like this. It's a little far out. It's a feature waiting for a problem. :-) > > In the old vars system, VAR: foo in addition to making getter and > > setter > > words, also setup up foo to be a symbol. In the system I changed it > > so "foo" > > is used as the variable. > I also don't like this. Yeah, Chris made me think about this. > > The main reason I was defining a symbol foo was to > > for let, but I might remove let anyway. > You can make let compile, though. Well actually, it wasn't because of the let compile error that I was going to remove it. It's because I think it's clearer to write out what let was doing. Let was another feature waiting for a problem. I didn't really use it that much. > > I might make a parsing word for something like let: > > > > (( a b c )) will expand into >c >b >a > > > > : foo (( a b c )) > > > > a> b> * a> c> * + b> - ; > I don't like this either :-) That's another far out thing. Just messing around. The stuff that "you don't like" I definately acknowledge as being experimental. Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On Thursday 11 January 2007 21:52, Chris Double wrote: > > In the system I changed it so "foo" is used as the variable. > Isn't using a symbol the right thing though? Using a string means you > can get clashes with any other file that uses the same string name as > a variable. Chris, Wow, you have a good point! I hadn't thought about this. The reason I wanted to move away from symbols is that it's easy to clash with existing things like word names and tuple names. Clashing with tuple names hasn't caused a problem for me yet, but it seems weird. So about using strings for variables. On the one hand, protection of the variable will happen via explicit scoping setup by the programmer. I'll have to look at places where I've used VAR: in my code to see if string based ones would cause a problem. Hmm. It's probably better to stick with symbols. :-) : foo ( a b c -- ) [ >c >b >a ... ] with-scope ; That is one usage pattern that is common for me, with the following characteristics: 1 - foo is not recursive; 2 - the only references to the variables a, b, and c, happen via the a> b> and c> words directly in the body of foo. That is, we aren't setting them for the sake of words called in the body of foo which reference a, b, or c, taking advantage of dynamic scope. That is a very nice clean pattern. String based variables would work well for this kind of usage. The problem is with words which reference variables and expect their value to be set in a way that dynamic scope is utilized. I think the simple foo pattern above is close to the model of Scheme. Moreover, if the words used in the body of foo stick to using >>foo (the set* version which searches up the namestack) then you get even closer to Scheme. One area where modeling the Scheme way breaks down is when you make foo recursive: : foo ( a b c -- ) [ >c >b >a ... foo ... ] with-scope ; Each time it recurs you add a level to the namestack! Scheme implementations are supposed to be smart enough to run foo in bounded memory as long as the foo is a tail call. If you know that the call to foo is a tail call, you can do this: : foo ( a b c -- ) [ (foo) ] with-scope : (foo) ( a b c -- ) >c >b >a ... (foo) ... ; Neato. So the scope is established by foo and things run bounded via (foo). What about situations like this: (define (a x y z) ... (b) ; tail call ...) (define (b x y z) ... (c) ; tail call ...) (define (c x y z) ... (a) ; tail call ...) Scheme is expected to run that chain in bounded space too. How about the Factor version? If entry to that set of functions only happens via a then: : a ( x y z -- ) [ (a) ] with-scope : (a) ( x y z -- ) >z >y >x ... (b) ... ; : (b) ( x y z -- ) >z >y >x ... (c) ... ; : (c) ( x y z -- ) >z >y >x ... (a) ... ; I wonder if that is an accurate enough modeling of the Scheme idiom. What about internal defines? (define (foo) (define (a) ...) (define (b) ...) (define (c) ...) (list (a) (b) (c))) : foo ( -- ) [ [ ... ] >a [ ... ] >b [ ... ] >c #a #b #c 3array ] with-scope ; Does that one hold up? Factor is a language that can support different programming styles. Besides applying Factor to practical problems, I think it is up to the community to explore the power of Factor. If I'm not being a stack purist then it's OK because there aren't any language police. Actually there are language police out there but they are powerless. I hope nobody interprets my suggestions as wanting to impose new idioms on others. We're all here because we're open minded enough to use Factor. It would be ironic to wear straightjackets now that we've come all this way. :-) So let's get on with the use and abuse of Factor. :-D Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
On 11-Jan-07, at 6:45 PM, Eduardo Cavazos wrote: > > : #foo ( -- ... ) ! Call the value of foo. E.g. "foo" get call I don't like this. > > In the old vars system, VAR: foo in addition to making getter and > setter > words, also setup up foo to be a symbol. In the system I changed it > so "foo" > is used as the variable. I also don't like this. > The main reason I was defining a symbol foo was to > for let, but I might remove let anyway. You can make let compile, though. > I might make a parsing word for something like let: > > (( a b c )) will expand into >c >b >a > > : foo (( a b c )) > a> b> * a> c> * + b> - ; I don't like this either :-) Slava - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
> In the system I changed it so "foo" is used as the variable. Isn't using a symbol the right thing though? Using a string means you can get clashes with any other file that uses the same string name as a variable. Chris. -- http://www.bluishcoder.co.nz - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
(( )) seems cool, and I look forward to playing with it. I'd like to use variables when a single word duplicates and consumes an object many times, a very common case in my programs. I suspect, however, that only one object in a word's stack effect typically needs this treatment. Is there a middle ground where only one object is saved to a libs/ vars style variable without needing a separate (and global) VAR: declaration? Yuuki On Jan 11, 2007, at 4:37 PM, Daniel Ehrenberg wrote: > The problem with your (( )) macro is that it isn't automatically > scoped, and could lead to errors or confusion. Also, it encourages > abuse of variables, and is just unnecessary. > > On 1/11/07, Eduardo Cavazos <[EMAIL PROTECTED]> wrote: >> Hello, >> >> I'm working on a new vars vocabulary. This one works like so: >> >> VAR: foo >> >> That will generate the following words: >> >> : foo> ( -- val ) ! getter >> >> : >foo ( val -- ) ! setter >> >> : >>foo ( val -- ) ! set using set* >> >> : >>>foo ( val -- ) ! set using set-global >> >> And if you aren't already squirming, here's this one: >> >> : #foo ( -- ... ) ! Call the value of foo. E.g. >> "foo" get call >> >> In the old vars system, VAR: foo in addition to making getter and >> setter >> words, also setup up foo to be a symbol. In the system I changed >> it so "foo" >> is used as the variable. The main reason I was defining a symbol >> foo was to >> for let, but I might remove let anyway. >> >> I might make a parsing word for something like let: >> >> (( a b c )) will expand into >c >b >a >> >> : foo (( a b c )) >> a> b> * a> c> * + b> - ; >> >> Ed >> >> - >> >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to >> share your >> opinions on IT & business topics through brief surveys - and earn >> cash >> http://www.techsay.com/default.php? >> page=join.php&p=sourceforge&CID=DEVDEV >> ___ >> Factor-talk mailing list >> Factor-talk@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/factor-talk >> > > -- > --- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDEV > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] The use and abuse of variables
The problem with your (( )) macro is that it isn't automatically scoped, and could lead to errors or confusion. Also, it encourages abuse of variables, and is just unnecessary. On 1/11/07, Eduardo Cavazos <[EMAIL PROTECTED]> wrote: > Hello, > > I'm working on a new vars vocabulary. This one works like so: > > VAR: foo > > That will generate the following words: > > : foo> ( -- val ) ! getter > > : >foo ( val -- ) ! setter > > : >>foo ( val -- ) ! set using set* > > : >>>foo ( val -- ) ! set using set-global > > And if you aren't already squirming, here's this one: > > : #foo ( -- ... ) ! Call the value of foo. E.g. "foo" get call > > In the old vars system, VAR: foo in addition to making getter and setter > words, also setup up foo to be a symbol. In the system I changed it so "foo" > is used as the variable. The main reason I was defining a symbol foo was to > for let, but I might remove let anyway. > > I might make a parsing word for something like let: > > (( a b c )) will expand into >c >b >a > > : foo (( a b c )) > a> b> * a> c> * + b> - ; > > Ed > > - > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] The use and abuse of variables
Hello, I'm working on a new vars vocabulary. This one works like so: VAR: foo That will generate the following words: : foo> ( -- val ) ! getter : >foo ( val -- ) ! setter : >>foo ( val -- ) ! set using set* : >>>foo ( val -- ) ! set using set-global And if you aren't already squirming, here's this one: : #foo ( -- ... ) ! Call the value of foo. E.g. "foo" get call In the old vars system, VAR: foo in addition to making getter and setter words, also setup up foo to be a symbol. In the system I changed it so "foo" is used as the variable. The main reason I was defining a symbol foo was to for let, but I might remove let anyway. I might make a parsing word for something like let: (( a b c )) will expand into >c >b >a : foo (( a b c )) a> b> * a> c> * + b> - ; Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] Compiler error in libs/vars
There's no error, Ed, you just wrote your code wrong. Set takes two things, and each provides one, so there *is* an unbalanced branch. Each, deep in its implementation, uses (repeat), and the compiler is just showing you that. That's where the actual unbalanced branch takes place, since it is all inlined. On 1/11/07, Eduardo Cavazos <[EMAIL PROTECTED]> wrote: > Slava, > > I get a compiler error when loading libs/vars. It complains about unbalanced > branches in (repeat) and the call chain goes up to let. But let never calls > that word directly. It get's there from each. Do you know what's going on? > > Paste this into the listener: > > : let ( vars body -- result ) > [ >r [ set ] each r> call ] with-scope ; > > \ let compile > > and you'll see the error. > > Ed > > - > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ___ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] Compiler error in libs/vars
Slava, I get a compiler error when loading libs/vars. It complains about unbalanced branches in (repeat) and the call chain goes up to let. But let never calls that word directly. It get's there from each. Do you know what's going on? Paste this into the listener: : let ( vars body -- result ) [ >r [ set ] each r> call ] with-scope ; \ let compile and you'll see the error. Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] reload
On 11-Jan-07, at 3:51 PM, Eduardo Cavazos wrote: > Slava, > > It would be nice if \ word reload actually only loaded the > specified word. Too difficult and not worth the hassle. > > If running the file has side effects then reload can cause problems. This is the actual problem. Remember our discussion on top-level forms -vs- file out. > > a b c d e are words in a file. For debugging purposes you have done > a watch on > some of them. You fix the problem with word d so you do \ d reload. > Now all > your watches are reset. It would be nice to toggle watch off as > well as on > and not have to resort to reload. You described a problem in watch. Advice needs to persist, and there should be a way to remove it other than reloading. Slava - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] reload
Slava, It would be nice if \ word reload actually only loaded the specified word. There are two good reasons for this. If running the file has side effects then reload can cause problems. a b c d e are words in a file. For debugging purposes you have done a watch on some of them. You fix the problem with word d so you do \ d reload. Now all your watches are reset. It would be nice to toggle watch off as well as on and not have to resort to reload. Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
Re: [Factor-talk] menu reloading
Chris, Here's a common sense solution: add a "reload menus" item to the root-menu. :-) Of course, this works because the reload itself is kicked off from within the thread that is in the same namespace as the original menus. I think this is the "right thing". { { "xterm" [ "xterm &" system drop ] } { "Firefox" [ "firefox &" system drop ] } { "xclock"[ "xclock &" system drop ] } ... { "Reload menus" [ root-menu reload ] } } >root-menu You'll have to add USE: definitions to the factory-rc. And a problem is that if there's a problem when reloading, you won't get a notification. In that case you'll just have to screen -r to debug it. It would be better for the menu item to be { "Reload factory-rc" [ factory-rc reload ] } But I don't have anything in libs/vocabs to support reloading vocabularies by name. Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk
[Factor-talk] menu reloading
Chris, Just to clarify, if you make a simple .xsession which just launches an xterm and then do: ./f -shell=tty USE: factory f start-factory then you can edit the menus in factory-rc, do a \ apps-menu reload in that terminal and it should work. If you start factory like this: ./f -shell=tty -e='USE: factory f start-factory' Then menu reloading doesn't work. Slava, can you explain why -e=expr is different from running the expr in the listener? Ed - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk