Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #58868

Re: excercise from Robert L, please comment

From "HAA" <someone@microsoft.com>
Newsgroups comp.lang.forth
Subject Re: excercise from Robert L, please comment
Date 2017-05-09 13:20 +1000
Organization Aioe.org NNTP Server
Message-ID <oerchn$161p$1@gioia.aioe.org> (permalink)
References <oekb0j$f1b$1@dont-email.me> <40386644-986d-4f11-9d55-13daacc108cf@googlegroups.com>

Show all headers | View raw


Yet another using lib functions you may already have.

\ lib functions

: +string  ( a1 u1 a2 u2 -- a2 u3)  \ append string
  2swap swap 2over + 2 pick cmove + ;

: split ( a u c -- a2 u2 a3 u3 )  \ split at char
  >r 2dup r> scan 2swap 2 pick - ;

: c/string ( a u -- a2 u2 char )  \ extract start char
  1 /string over 1- c@ ;

: alpha? ( char -- flag )  upcase [char] A - #26 u< ;

\ version 1 - using HOLD buffer
: trivia ( a u -- a2 u2 a3 u3 )
  0 >r  pad 0
  begin  2swap bl skip  dup while
    bl split
    begin  2dup 0<> swap c@ alpha? and
    while  c/string >r  repeat  bl >r
    2rot +string s"  " 2swap +string
  repeat 2drop
  <#  begin  r> ?dup while  hold  repeat
  0 0 #> -trailing ;

s" Xy21 Z17 T43" 2dup cr type cr trivia cr type cr type
Xy21 Z17 T43
Xy Z T
21 17 43  ok

\ version 2 - for larger strings

: cappend ( c adr -- )  dup c@ 1+  2dup swap c!  + c! ;

here unused + 256 - value POCKET  \ temp storage

: +pocket ( c -- )  pocket  cappend ;

: trivia ( a u -- a2 u2 a3 u3 )
  0 pocket c!  pad 0
  begin  2swap bl skip  dup while
    bl split
    begin  2dup 0<> swap c@ alpha? and
    while  c/string +pocket  repeat  bl +pocket
    2rot +string s"  " 2swap +string
  repeat 2drop
  pocket count -trailing ;


Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

excercise from Robert L, please comment Andreas Klimas <klimas@w3group.de> - 2017-05-06 13:14 +0200
  Re: excercise from Robert L, please comment Alex <alex@rivadpm.com> - 2017-05-06 13:14 +0100
  Re: excercise from Robert L, please comment Andreas Klimas <klimas@w3group.de> - 2017-05-06 16:44 +0200
    Re: excercise from Robert L, please comment Alex <alex@rivadpm.com> - 2017-05-06 19:55 +0100
      Re: excercise from Robert L, please comment Alex <alex@rivadpm.com> - 2017-05-06 20:26 +0100
        Re: excercise from Robert L, please comment Andreas Klimas <klimas@w3group.de> - 2017-05-07 23:08 +0200
    Re: excercise from Robert L, please comment Ron Aaron <rambamist@gmail.com> - 2017-05-07 07:46 +0300
      Re: excercise from Robert L, please comment Ron Aaron <rambamist@gmail.com> - 2017-05-07 07:54 +0300
    Re: excercise from Robert L, please comment hughaguilar96@gmail.com - 2017-05-07 09:15 -0700
  Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-08 11:00 -0700
  Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-08 11:52 -0700
    Re: excercise from Robert L, please comment "HAA" <someone@microsoft.com> - 2017-05-09 13:20 +1000
      Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-10 00:26 -0700
        Re: excercise from Robert L, please comment "HAA" <someone@microsoft.com> - 2017-05-11 17:07 +1000
          Re: excercise from Robert L, please comment humptydumpty <ouatubi@gmail.com> - 2017-05-11 00:25 -0700
  Re: excercise from Robert L, please comment Julian Fondren <julian.fondren@gmail.com> - 2017-05-08 21:40 -0700
    Re: excercise from Robert L, please comment Julian Fondren <julian.fondren@gmail.com> - 2017-05-08 21:46 -0700

csiph-web