00:00:00 --- log: started forth/09.05.29 01:14:14 --- quit: nighty__ (Client Quit) 01:26:05 --- quit: sunwukong ("bye") 03:02:56 --- join: mark4 (n=mark4__@ip70-162-227-36.ph.ph.cox.net) joined #forth 03:04:06 --- quit: I440r (Read error: 110 (Connection timed out)) 03:46:06 --- join: GeDaMo (n=gedamo@212.225.121.248) joined #forth 04:03:18 --- quit: proteusguy (Read error: 110 (Connection timed out)) 04:25:57 --- join: proteusguy (n=proteusg@61.7.144.97) joined #forth 04:41:12 --- quit: GeDaMo ("Leaving.") 05:02:13 --- join: tathi (n=josh@dsl-216-227-91-166.fairpoint.net) joined #forth 05:26:32 --- join: schme (n=marcus@c83-249-82-162.bredband.comhem.se) joined #forth 05:35:11 --- join: sunwukong (n=vukung@125-14-81-177.rev.home.ne.jp) joined #forth 08:00:24 --- join: SonOfLilit (n=aursaraf@bzq-79-183-229-21.red.bezeqint.net) joined #forth 08:01:02 Hello 08:01:54 I just started to teach myself forth 08:02:05 I'm trying to reverse a string in place 08:02:56 I loop calling a word I called s-switch ( base i1 i2 -- ) which switches the indexes i1 and i2 in the string at address base 08:03:09 this word is ugly 08:03:13 REALLY ugly 08:03:29 and I've tried three different approaches, and it's still ugly 08:04:18 stack manipulation just doesn't feel right for such words 08:04:22 how would you guys implement it? 08:21:11 ah, finally, I found a clean way 08:22:00 value i2 value i1 value b b i2 s@ b i1 s@ b i2 s! b i1 s! 08:22:31 where s@ ( addr index -- c ) , s! ( character addr index -- ) 08:23:04 does this overwrite the previous value or leak like crazy? 08:45:50 --- quit: mark4 (Read error: 104 (Connection reset by peer)) 08:46:28 --- join: mark4 (n=mark4__@ip70-162-227-36.ph.ph.cox.net) joined #forth 08:50:47 Er...comma allots space on the heap, if that's what you mean 08:51:20 no, there's no comma in my code 08:51:28 the comma is part of the english explaining it 08:51:33 ah 08:51:45 I only give stack effect diagrams for s@ and s! as they are trivial 08:51:52 --- join: GeDaMo (n=gedamo@212.225.121.248) joined #forth 08:51:53 sure 08:52:11 : s@ chars + c@ ; : s! chars + c! ; 08:52:16 I mean value 08:52:30 does VALUE allocate new memory every time? 08:52:41 allot* 08:53:29 and how would you write S-SWITCH ? 08:53:54 only when you define a value initially 08:54:02 not when you access it or change it, of course 08:54:13 ok, so no crazy memory leak :) 08:54:28 and this seems like the way to go on a forth system without locals 08:54:34 yeah, sorry. I didn't take the time to follow your code carefully. 08:54:41 it's ok :) 08:54:45 I don't think the stack manipulation for s-switch should be bad... 08:54:58 can you give it a go? 08:55:05 yup, thinking 08:56:15 hmm...maybe it is that bad. :) 08:56:28 might be better if you just gave it two addresses? 08:57:50 : exchange ( addr1 addr2 -- ) over @ over @ rot ! swap ! ; 08:57:59 er...I mean c@ and c! 08:59:58 and...that's still wrong 09:01:07 What problem are you trying to solve? 09:01:18 Gave myself an excersize 09:01:20 he's trying to reverse a string in place 09:01:27 reversing a string in place 09:01:39 we're working on a clean word to reverse two characters 09:02:20 it's true that stack manipulation often isn't great for this sort of thing 09:02:37 too many things to deal with at once 09:03:02 Why doesn't your exchange word work for that? 09:03:15 it replaces each location with itself 09:03:16 it does, just needs another swap (before rot). 09:06:28 : exchange-addrs ( addr1 addr2 -- ) over c@ over c@ swap rot c! swap c! ; 09:06:28 : exchange ( addr i1 i2 -- ) >r over r> chars + >r chars + r> exchange-addrs; 09:06:28 : exchange-addrs ( addr1 addr2 -- ) over c@ over c@ swap rot c! swap c! ; 09:06:28 : exchange ( addr i1 i2 -- ) >r over r> chars + >r chars + r> exchange-addrs; 09:06:28 : exchange-addrs ( addr1 addr2 -- ) over c@ over c@ swap rot c! swap c! ; 09:06:35 uh, sorry 09:07:02 connection problems combined with stupid irc client made me think paste of two lines doesn't work 09:08:03 yeah, this workd 09:08:05 works* 09:08:37 gotta say the VALUE version is much cleaner though 09:09:02 or is my exchange at fault? 09:09:47 no, I think there's just too much stuff on the stack for it to be comfortable 09:10:47 you could write it using a bunch of different stack-manipulation words, but I don't know that any of them are any better. 09:11:12 2dup c@ swap c@ rot c! swap c! 09:11:45 no, I'm talking about exchange, not exchange-addrs 09:12:21 oh, I see. 09:13:03 I think I'd try to write the loop to give you addrs rather than indices 09:13:16 I agree 09:14:22 well, here it is then for your hacking pleasure: 09:14:56 : reverse ( addr n -- ) dup 2 / 0 do 2dup i - 1- i exchange loop 2drop ; 09:15:10 I can't think of a better way to write it than factoring out the indices-to-addresses code 09:15:37 wait, maybe I can 09:15:40 just a moment 09:16:04 you could do the calculation in the loop, where you have `I` available instead of having to keep everything on the stack 09:16:17 yeah 09:17:58 : c+ chars + ; 09:17:58 : exchange ( addr1 addr2 -- ) over c@ over c@ swap rot c! swap c! ; 09:17:58 : reverse ( addr n -- ) dup 2 / 0 do 2dup i - 1- c+ over i c+ exchange loop 2drop ; 09:18:14 much better 09:18:21 There's a 2/ word 09:18:44 yay, so now my code is 80 chars wide and not 81 :) 09:18:45 It does a right shift rather than a division 09:19:18 but... it doesn't pass the test 09:19:22 let me have another look 09:21:18 ok, or you could use indices and do : exchange ( addr i1 i2 -- ) rot tuck + >r + r> exchange-addrs ; 09:21:46 er...well, unless you want chars in there 09:22:02 what does tuck do? 09:22:11 ( a b -- b a b ) 09:22:17 swap over 09:22:21 mm 09:25:44 this fixes my bug: 09:25:45 : c+ chars + ; 09:25:45 : exchange ( addr1 addr2 -- ) over c@ over c@ swap rot c! swap c! ; 09:25:45 : reverse ( addr n -- ) dup 2/ 0 do 2dup over i c+ rot rot i 1+ - c+ exchange loop 2drop ; 09:26:07 is there a short for rot rot? 09:26:37 --- quit: Deformative (Remote closed the connection) 09:26:43 -rot 09:28:17 --- quit: sunwukong ("bye") 09:30:36 --- join: Deformative (n=joe@c-71-238-45-45.hsd1.mi.comcast.net) joined #forth 09:33:04 --- join: bifft (n=sixforty@adsl-070-148-228-084.sip.asm.bellsouth.net) joined #forth 09:37:32 --- part: bifft left #forth 11:04:40 --- quit: Al2O3 ("I'm heading out, will be back online soon") 12:33:20 --- quit: schme (Read error: 113 (No route to host)) 13:15:18 --- join: kar8nga (n=kar8nga@e-62.vc-graz.ac.at) joined #forth 14:17:56 --- join: aguaithefreak (n=aguai@114-42-211-66.dynamic.hinet.net) joined #forth 14:18:34 --- quit: aguaithefreak (Client Quit) 14:35:51 --- quit: GeDaMo ("Leaving.") 15:02:16 --- quit: sleepydog (anthony.freenode.net irc.freenode.net) 15:02:17 --- quit: madgarden (anthony.freenode.net irc.freenode.net) 15:03:28 --- join: sleepydog (n=david@64-252-82-123.adsl.snet.net) joined #forth 15:03:28 --- join: madgarden (n=madgarde@CPE001d7e527f89-CM00159a65a870.cpe.net.cable.rogers.com) joined #forth 15:08:01 --- join: maht (n=maht__@85-189-31-174.proweb.managedbroadband.co.uk) joined #forth 15:12:38 --- quit: kar8nga (Remote closed the connection) 15:19:57 --- quit: maht_ (Read error: 110 (Connection timed out)) 16:51:59 --- quit: ENKI-][ ("WeeChat 0.2.6") 16:57:26 --- join: ENKI-][ (n=weechat@c-71-234-190-248.hsd1.ct.comcast.net) joined #forth 17:09:15 --- quit: sleepydog ("leaving") 19:56:07 --- join: Dialupas (n=Rodo1@v-209-98-172-217.mn.visi.com) joined #forth 19:56:49 Anyone around? 20:00:24 --- quit: Dialupas (Read error: 104 (Connection reset by peer)) 20:10:52 --- join: Al2O3 (n=Al2O3@24.9.43.112) joined #forth 20:38:34 --- quit: Al2O3 ("I'm heading out, will be back online soon") 20:47:51 --- join: Deformati (n=joe@c-71-238-45-45.hsd1.mi.comcast.net) joined #forth 21:19:50 --- join: Def (n=joe@c-71-238-45-45.hsd1.mi.comcast.net) joined #forth 21:19:51 --- quit: Deformati (Read error: 54 (Connection reset by peer)) 21:27:32 --- join: crc (n=charlesc@c-68-80-139-0.hsd1.pa.comcast.net) joined #forth 21:29:18 --- quit: crc (Client Quit) 22:47:53 --- quit: mark4 (Read error: 54 (Connection reset by peer)) 22:49:30 --- join: mark4 (n=mark4__@ip70-162-227-36.ph.ph.cox.net) joined #forth 23:05:34 --- quit: nighty^ ("Disappears in a puff of smoke") 23:59:59 --- log: ended forth/09.05.29