tag:blogger.com,1999:blog-8513438391157777465.post6846979489978389621..comments2023-04-07T05:56:45.278-07:00Comments on Re: Factor: Interpolatemrjbq7http://www.blogger.com/profile/06842721076008035602noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-8513438391157777465.post-51687977980816241502015-04-20T16:59:43.730-07:002015-04-20T16:59:43.730-07:00@ruv, I love opinions!
It's seems to be one o...@ruv, I love opinions!<br /><br />It's seems to be one of those areas where you could go either way. For example, we made the ``printf`` word go by order of arguments:<br /><br />IN: scratchpad 192 168 0 1 "%s.%s.%s.%s" printf <br />192.168.0.1<br /><br />And we have the ``boa`` constructor, do the same (so arguments are ordered the same way they are defined):<br /><br />IN: scratchpad TUPLE: foo a b c ;<br />IN: scratchpad 1 2 3 foo boa .<br />T{ foo { a 1 } { b 2 } { c 3 } }<br /><br />But, as you pointed out, when we have numbered arguments like in ``npick``, it is indexed from the top of the stack.<br /><br />I think I'll keep it the way it is for now, but definitely worth discussing what would be more intuitive to users.mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-6185886685092834112015-04-20T16:15:21.724-07:002015-04-20T16:15:21.724-07:00@mrjbq7, if you mean Python's example: octets ...@mrjbq7, if you mean Python's example: octets = [192, 168, 0, 1]; '{:02X}{:02X}{:02X}{:02X}'.format(*octets)<br /># -- 'C0A80001'<br />It can be rewritten as<br />'{:02X}{:02X}{:02X}{:02X}'.format( 192, 168, 0, 1)<br />And that should corresponds to Factor's code like:<br />1 0 168 192 "${}.${}.${}.${}" # -- 192.168.0.1<br /><br />(Since the first argument in prefix language corresponds to the top argument in postfix one).<br /><br />But according to your example in the blogpost we will get 1.0.168.192 in such case.<br /><br />Although, don't bother, it is just my opinion =)ruvhttps://www.blogger.com/profile/05501175832748635405noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-79862762900852031912015-04-20T14:46:57.303-07:002015-04-20T14:46:57.303-07:00Okay, so I also added anonymous by-order-of-argume...Okay, so I also added anonymous by-order-of-arguments referencing, a bit similar to how Python does it, and an example to this blog post.mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-62515534538398022632015-04-20T13:59:29.824-07:002015-04-20T13:59:29.824-07:00@mrjbq7, yes in my implementation it always implie...@mrjbq7, yes in my implementation it always implies the top of stack. If you need second parameter you can use (in terms of Factor) {swap}, {2 nrot}, or {2 npick} depends on. So, this {} structure just executes its code and takes the top item from the stack.ruvhttps://www.blogger.com/profile/05501175832748635405noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-44730299934610610362015-04-20T13:05:35.029-07:002015-04-20T13:05:35.029-07:00@ruv, I love the idea of having generic code insid...@ruv, I love the idea of having generic code inside "{}". When you use anonymous reference, does it always imply the top of the stack?<br /><br />I'm re-committing the patch from earlier. It is nice that {0} always refers to the same argument position, and is similar to npick.<br /><br />Thanks for the feedback!mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-361307273893094312015-04-20T12:23:53.910-07:002015-04-20T12:23:53.910-07:00OTOH, in my own implementation of string interpola...OTOH, in my own implementation of string interpolation I do refer to parameters from the stack anonymously only. <br />I.e. {} would mean to take parameter from the top of stack, and {dup} means copy that parameter. So, it allows to use any simple code inside {}.ruvhttps://www.blogger.com/profile/05501175832748635405noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-12580842008956078862015-04-20T12:17:00.364-07:002015-04-20T12:17:00.364-07:00@mrjbq7, re point (3) — it doesn't matter, in ...@mrjbq7, re point (3) — it doesn't matter, in my opinion.ruvhttps://www.blogger.com/profile/05501175832748635405noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-50353175355291731532015-04-20T12:10:43.714-07:002015-04-20T12:10:43.714-07:00The argument against numbering from tail: string m...The argument against numbering from tail: string may be quite long. And when you see ${2} you actually do not know, what the parameter it refers to. Because it depends on number of the used parameters. If there 3 used parameters, it refers to one, and if there 4 parameters used it refers to another.<br />Re convention — Factor alredy has "npick" word that use numbering from the stack top (and from 1). So, numbering from 0 is question too.ruvhttps://www.blogger.com/profile/05501175832748635405noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-73473535114227638082015-04-20T11:37:47.505-07:002015-04-20T11:37:47.505-07:00Seems like there are votes for both ways, I'm ...Seems like there are votes for both ways, I'm just going to keep the "ninterpolate" way for right now. I think usability hinges on a few questions:<br /><br />1) Is it easier to read numbered the old or new way?<br /><br />2) Is there a convention somewhere we can compare with?<br /><br />3) Do you mostly write format strings that look at arguments deeper in the stack before ones that are on the top of the stack? (Meaning, will you see a lot of "{2}, {1}, {0}", vs "{0}, {1}, {2}" and does that matter?)<br /><br />But, maybe we can give it some thought before releasing 0.98. Thanks!mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-76739140709178467502015-04-20T11:15:27.351-07:002015-04-20T11:15:27.351-07:00This comment has been removed by the author.mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-26962644402424306642015-04-20T11:00:24.493-07:002015-04-20T11:00:24.493-07:00Hi @ruv, we could definitely do that easily, it .
...Hi @ruv, we could definitely do that easily, it .<br /><br />The practical reason why I did that was to be compatible with a word we used to have called "ninterpolate" that only worked with stack arguments and it numbered them that way:<br /><br />https://github.com/slavapestov/factor/blob/760126525be7f9a2793908e0067c08609ee4f9e8/basis/interpolate/interpolate.factor#L46<br /><br />Lemme ask @erg and see what he thinks, too.mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-8513438391157777465.post-54566609619155353772015-04-20T10:44:31.190-07:002015-04-20T10:44:31.190-07:00Hello!
Why don't you count arguments from the ...Hello!<br />Why don't you count arguments from the top of stack?<br />I'd prefer (having Forth background): <br />"James" "Bond" "${0}, ${1} ${0}" interpolate # -- "Bond, James Bond"ruvhttps://www.blogger.com/profile/05501175832748635405noreply@blogger.com