2022-03-01 14:01:19 if i have quotations, and already removed loops (in favor of combinators to express common looping patterns), is there any enormously-strong reason to not do the same for conditionals? 2022-03-01 14:01:23 or is this haskellbrain slipping in 2022-03-01 14:05:20 eg instead of IF foo ELSE bar THEN, write { foo } { bar } COND 2022-03-01 14:05:35 DUP IF foo ELSE DROP bar THEN => { foo } { bar } ?COND 2022-03-01 14:06:01 IF foo THEN => { foo } WHEN 2022-03-01 14:06:22 DUP IF foo ELSE DROP THEN => { foo } ?WHEN 2022-03-01 17:38:27 remexre: Does your Forth have the ?DUP word? 2022-03-01 17:39:02 Oh, never mind - that Forth was what you replaced. I see now. 2022-03-01 17:40:02 I've thought about different styles of conditional handling. These days my habit is to factor the conditional stuff into its own word and put a conditional return at the beginning of the word. 2022-03-01 17:40:35 what's that lok like? 2022-03-01 17:40:37 It inverts the condition - if I want to execute on true, then I return on false. 2022-03-01 17:40:42 It might something like 2022-03-01 17:40:56 : foo ?0; ...stuff to do if true... ; 2022-03-01 17:41:05 Actually my word is 0=; 2022-03-01 17:41:19 : foo 0=; ...stuff to do if true... ; 2022-03-01 17:41:37 I might also put a ? in the name of foo, to indicate it makes a decision. 2022-03-01 17:41:42 But that's just a style choice. 2022-03-01 17:41:54 ahhh 2022-03-01 17:41:55 makes sense 2022-03-01 17:42:12 I feel like my definitions are noticeably shorter with those in use. 2022-03-01 17:42:35 I also have conditional two-level returns, and I sort of build "vertical control structures" with all that. 2022-03-01 17:42:42 : 0=? r> drop ; 2022-03-01 17:42:43 ? 2022-03-01 17:43:05 I've started to evolve standard multi-level "patterns" that I use over and over. 2022-03-01 17:43:11 Yes, basically, except mine's a primitive. 2022-03-01 17:43:16 that's common i think 2022-03-01 17:43:16 yea 2022-03-01 17:43:44 i have something similar in that i have implicit conditional loops in the form of a word called +;; and -;; 2022-03-01 17:43:45 I have a lot of them, for a lot of conditions. I wrote a python script to generate the assembly source for those, into an include file for nasm. 2022-03-01 17:44:15 :-) 2022-03-01 17:44:20 I like terse symbolic names. 2022-03-01 17:44:31 Deliver me from THIS_IS_MY_WORD_TO_DO_FOO 2022-03-01 17:44:47 yup 2022-03-01 17:44:58 +;; is basically just recurse if false 2022-03-01 17:45:30 Ah, nice. I have a word called ME that jumps to the most recently defined word, so it's how I implement tail recursion. 2022-03-01 17:45:42 The advantage of having a special name is that I can then have "conditional ME" words. 2022-03-01 17:45:47 ye, mine just calculates it manually 2022-03-01 17:45:58 i don't use a forth impl i wrote 2022-03-01 17:46:02 so it's just using LATEST 2022-03-01 17:46:47 Some of my progrmamer friends complain about my word names - say they're unreadable. But... they're readable to me, because I've learned them. 2022-03-01 17:46:53 That's who it's for anyway. 2022-03-01 17:47:26 I invented a "convention" under which I prefix existing word names with . 2022-03-01 17:47:38 Those are new words, separate dictionary entries. Nothing automated. 2022-03-01 17:47:54 But what they always do is the same thing the base word does, except they remove one less item from the stack than the base word. 2022-03-01 17:48:20 So if =; is a return if equal that removes the two elements, .=; is a return if equal word that keeps the lower element. 2022-03-01 17:48:23 huh, neat 2022-03-01 17:48:30 Very nice for applying a sequence of comparisons to a data variable. 2022-03-01 17:48:36 uxn (a forth like project) has something like that 2022-03-01 17:48:42 You get rid of the comparison item, but keep the actual datum. 2022-03-01 17:49:03 you suffix a k to do that 2022-03-01 17:49:17 Was handy in my NUMBER word, where I had to compare the character to a variety of different things. 2022-03-01 17:51:09 Putting that all together (the single and double conditional returns and the . prefix), I was able to get my next string char on the stack and then say something like ?0-9 ?A-F ?a-f .? -? 2022-03-01 17:51:31 Each word checked the char, if it matched did what it was supposed to do and then DOUBLE returned, else just returned. 2022-03-01 17:51:39 Single return sent me to the next test - double return sent me out. 2022-03-01 17:51:55 that's neat! 2022-03-01 17:52:09 That's one of those patterns that sort of emerged. 2022-03-01 18:24:10 remexre KipIngram, eris[m] , can you please paste some code using those ( COND +;; ) words? I would like to see how the forth code looks with them. 2022-03-01 18:24:50 i don't have a big body 2022-03-01 18:24:54 i had a funky little lists example 2022-03-01 18:25:58 : >end cdr dup cdr +;; 2022-03-01 18:26:04 cdr being cell+ @ 2022-03-01 18:26:23 which gets the second value from a pair implemented as a pointer 2022-03-01 18:27:12 i dont really preserve a lot f code i work with 2022-03-01 18:27:56 : length >r cdr dup cdr r> 1+ swap +;; 2022-03-01 18:28:00 loop body 2022-03-01 18:28:06 : length 0 length nip 1+ ; 2022-03-01 18:28:09 use of loop 2022-03-01 19:04:00 KipIngram: no, the optimizer I sketched out on paper used to have trouble with variable stack effects so I trained myself to always put a DROP in the ELSE 2022-03-01 19:04:36 (I have since fixed the optimizer's design, though it's not implemented yet) 2022-03-01 19:05:04 but yeah the ?COND and ?WHEN are basically ?DUP COND and ?DUP WHEN, respectively 2022-03-01 19:12:36 joe9: can send a proper example when I'm home, but the rewrites I wrote above are "pretty much it" 2022-03-01 20:34:40 in my forth, COND is `choose` and WHEN is `if`; I don't have combinators for ?COND or ?WHEN. An equivalent to ?WHEN might be worth adding based on a quick review of my sources.