00:00:00 --- log: started forth/11.04.17 00:29:41 --- quit: saper (Remote host closed the connection) 01:01:05 --- join: qFox (~C00K13S@5356B263.cm-6-7c.dynamic.ziggo.nl) joined #forth 01:03:43 --- part: DocPlatypus left #forth 01:31:17 --- join: saper (saper@wikipedia/saper) joined #forth 01:53:17 --- join: nHarzilei (harzi@camelot.germanistik.fu-berlin.de) joined #forth 01:53:22 hi 01:53:56 uhm, i only looked at forth a long time ago, but now i was reading this here: http://en.literateprograms.org/Fisher-Yates_shuffle_%28Forth%29 01:54:04 what's with the curly brackets? 01:54:34 where are they defined? do they actually assign variables, popping the inputs from the stack? 02:01:28 Nowhere, it is non-standard thing. 02:03:51 ASau: so any idea what kind of implementation the author used? 02:04:26 Yes, but the code doesn't comply style. 02:04:49 It is in Fortran style only written in Forth. 02:05:20 And literate programming doesn't help its clarity. 02:07:05 What do you want? 02:07:26 Just FYS or code in good style? 02:07:43 "FYS"? 02:09:47 actually i want to implement it in another remotely forth-like language 02:10:19 and searched for "fisher yates" "forth" and it came up with this and i was puzzled by the curly brackets 02:11:51 Then why don't you just take FYS code in language you understand? 02:13:54 i wanted to look if there's a good implementation. i agree picking from the array again and again looks a bit less optimal 02:14:31 and of course now that i looked i'm curious in which forth variantes the curly brackets thing occurs 02:14:52 They occur in many variants. 02:15:00 Only in different meanings. 02:15:43 E.g. John Hayes' tester uses them. 02:17:26 I'm not sure how you want to avoid array fetch. 02:21:45 And you want to improve algorithm so that it doesn't use "choose random between" operation. 02:23:32 With random ( u -- u' ) where 0 <= u' < u, you can write it this way: 02:24:01 : shuffle ( ptr len ) times dup r random th over r th @swap repeat drop ; 02:33:57 heh, i guess your conciseness goes with the seasoned forth programmer. i just found another implementation and it also defines a randRange helper 02:34:23 What languages do you understand besides Forth? 02:35:15 perl, c, python, php, javascript, 6502 assembly ;) 02:35:23 java ;) 02:35:24 Alright, let it be C then. 02:35:46 nah, it's ok, i don't need an explanation of fisher yates 02:36:17 Consider you have "unsigned random(unsigned n)", not the standard one. 02:36:23 Well... 02:36:26 Let's rename it. 02:36:36 "unsigned rnd(unsigned)", alright? 02:36:53 Let it return random number in below its argument, 02:37:00 and zero for zero argument. 02:37:19 Then FYS is this: 02:38:22 unsigned i = len; while (i--) swap(&a[i], &a[rnd(i)]); 02:39:14 Do you understand the code? 02:39:19 i think you need to make sure you only swap with those that haven't already been swapped 02:39:40 Why? 02:40:15 Do you understand how the code above relates to description you reference? 02:44:30 Alright, minor correction :) 02:44:45 unsigned i = len; while (i) {swap(&a[i], &a[rnd(i)]); i--;} 02:45:29 or you can check for (i>=2). 02:45:58 Shuffling single-element array is rather stupid. 02:46:52 Whatever, there's space for nitpicking. 02:47:54 yeah, i'm just looking at the other implementation and look why its author needed the range 02:48:37 --- join: MayDaniel (~MayDaniel@unaffiliated/maydaniel) joined #forth 02:49:03 I think that this is how original algorithm was written, 02:49:26 and because of going from first element to last seems more natural. 02:49:52 But this isn't natural for some languages, thus I go from last to first. 02:57:54 --- quit: MayDaniel (Read error: Connection reset by peer) 03:08:52 hmm... 03:09:53 --- quit: nighty__ (Ping timeout: 240 seconds) 03:09:54 Alright, do you understand how this algorith works on sets? 03:10:09 : randomSubset ( ptr len num ) times dup r random the over r th @swap repeat ; should work, right? 03:10:47 Why do you need "num" parameter? 03:11:16 only get last num elements shufflen for less work when i only need num random elements out of the array 03:11:20 shuffled* 03:11:52 Well... 03:12:07 First, the definition you write is inconsistent with stack comment. 03:12:39 Second, if you use "random ( n -- n' )", it is broken. 03:13:20 ...when given three parameters, as stated in stack effect. 03:16:07 Do you understand that Forth doesn't check all those things for you? 03:17:52 yes 03:18:24 i'll see if i can find the sample (i think that's how the word should be called) solution myself 04:02:22 is times .. repeat actually standard forth? 04:08:25 No, but it is implementable. 04:11:51 Do you need definition? 04:19:06 that'd be nice 04:23:21 : ` postpone postpone ; immediate 04:23:21 : times ` >r ` begin ` r> ` ?dup ` while ` 1- ` >r ; immediate 05:03:24 --- join: MartianW (~Martian@unaffiliated/martianw) joined #forth 06:02:18 --- join: MayDaniel (~MayDaniel@unaffiliated/maydaniel) joined #forth 06:11:42 --- quit: MayDaniel (Read error: Connection reset by peer) 06:33:48 : th cells + ; 06:33:51 is that the definition? 06:39:54 Yes. 06:42:31 so this is actually 4p you are using there? 06:43:44 No. 06:43:51 I've forked from pforth. 06:44:17 i fork()ed from spoon.zip 06:48:51 --- join: kernalogs (~jackokrin@nat67.mia.three.co.uk) joined #forth 06:59:29 --- quit: xpololz (Remote host closed the connection) 07:12:03 --- part: kernalogs left #forth 07:39:07 --- join: MayDaniel (~MayDaniel@unaffiliated/maydaniel) joined #forth 07:45:40 --- quit: MayDaniel (Read error: Connection reset by peer) 07:57:05 --- join: foocraft (~dsc@89.211.214.110) joined #forth 07:59:43 --- join: nixness (~dsc@78.100.177.99) joined #forth 08:02:19 --- quit: foocraft (Ping timeout: 250 seconds) 09:09:31 --- quit: MartianW (Quit: Bye all.) 09:41:34 --- quit: nixness (Ping timeout: 260 seconds) 10:16:02 is it hard to make something like {{ 1 2 3 4 5 }} that returns an addr with those and the number of items? 10:30:55 What do you want exactly? 10:31:04 Create an array in heap? 10:36:47 i need to create it on the heap if i want an "anonymous" array, right? as regular , will only work with a name? some way to define a name would help as well, with addr and number of items ending up on the stack when i run it (i think that's done with does>) 10:37:21 i'm not picky, i just don't want to count my items 10:37:22 ;) 10:38:05 Well... Then make Forth count them. 10:38:10 variable cnt 10:38:16 : {{ 0 cnt ! ; 10:38:29 Hrm. 10:38:36 : {{ depth cnt ! ; 10:38:49 : }} depth cnt @ - ; 10:39:48 I hope you'll figure how to move those items from stack into dynamic memory yourself. 12:48:04 or use PostScript :) 13:12:01 --- quit: martinhex (Read error: Connection reset by peer) 13:12:01 --- join: martinhex (~mjc@93-97-29-243.zone5.bethere.co.uk) joined #forth 13:35:10 --- quit: qFox (Quit: Time for cookies!) 13:49:50 ASau: hmm... times only really works good because it counts to 0 13:51:04 --- join: grai (~grai@38.70.70.115.static.exetel.com.au) joined #forth 13:55:05 ASau: is there a reason it's not 13:55:36 nvm 14:01:42 Yes, that's the point. 14:01:59 It counts to zero because it is easier to and more effective. 14:04:14 ASau: yeah, but for just getting K random elements out of the array i need to count from len down to k 14:04:22 In particular, you don't need complex logic within your primitives that implement "do ... loop" 14:04:35 Well... You asked for FYS first. 14:04:48 yes, i'm not complaining 14:05:03 With incomplete FYS you do need more general looping constructs. 14:06:15 If you don't use FIG-style strict controls, you can do it like 14:07:21 n times last-n r < while ... repeap rdrop then 14:08:19 i was actually considering doing it with gforth u+do, but of course i'm curious if i can do it with begin .. while .. repeat instead of loop 14:08:21 (I think that this "search" idiom/pattern should be known.) 14:11:03 "strict controls"? because times already sets up while? 14:11:45 With FIG-style controls you can't use another "while", thus 14:11:45 you can't write common search idiom like 14:12:27 "begin more? while not-found? while next repeat found else not-found then" 14:16:35 Nothing stops you from writing FYS in its original form. 14:16:57 --- quit: ygrek (Ping timeout: 246 seconds) 14:19:49 I don't quite understand what your problem is. 14:20:23 Obviously, what you want goes beyond FYS. 14:20:32 But you don't tell it. 14:26:15 over in ircnet we have a channel where the bot can be programmed with oneliners in a forth-like dynamically typed toy language. this morning someone entered a word 7 rand 0 do userrandom ", SPAMM SAPAPAPAMMM SPAMMM" . say loop (. is concatenation there and say is type to irc channel)... despite the program being annoying anyway i thought that the possibility of people getting spammed twice is awfully inelegant as well. 14:27:37 What can I say? 14:28:24 Don't expose Turing-complete languages to possibly unfriendly users. 14:29:02 I'm going off-line now. 14:29:11 Gute Nacht! 14:29:14 thanks for your input :) 14:29:16 gn 14:31:59 regarding {{ ... }}, in retro this works: 14:32:00 : {{ ( "-an ) here 0 [ getToken dup "}}" compare [ drop 0 ] [ toNumber , 1+ -1 ] if ] while ; 15:22:31 so this is what i'll try now : ishuffle ( ptr len num ) over swap - to last-n times last-n r < while dup r@ random th over r@ th @swap repeat rdrop then 18:48:57 --- join: Fox78 (~fox@123.118.155.138) joined #forth 19:01:38 --- join: DocPlatypus (~skquinn@dsl253-084-031.hou1.dsl.speakeasy.net) joined #forth 19:57:41 --- join: foocraft (~dsc@178.152.70.10) joined #forth 20:11:13 --- join: cataska (~cataska@210.64.6.233) joined #forth 22:06:26 --- quit: foocraft (Quit: Leaving) 23:36:24 --- join: ygrek (debian-tor@gateway/tor-sasl/ygrek) joined #forth 23:59:59 --- log: ended forth/11.04.17