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


Groups > comp.lang.forth > #53708

:Re: confused newbie (in asbestos Y-fronts...)

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject :Re: confused newbie (in asbestos Y-fronts...)
Date 2017-01-03 17:14 +0000
Organization Aioe.org NNTP Server
Message-ID <o4gm68$msj$1@gioia.aioe.org> (permalink)

Show all headers | View raw


Martti Halminen wrote:

> > by James L. Noyes using XEmacs v.21.1.  I'm trying to write a bit of
> > code to return the root string of a word with a given ending.  (e.g
> > (suffix-match 'ing 'match) should return "match" (if no match then
> > "nil"))
> >
> > ;;;(I've labelled the ending 'e' and the word 'w')
> >
> > (defun suffix-match (e w)
> >     (if (string= (subseq (reverse w) 0 (length e)) (reverse e))
> >     (subseq w 0 (- (length w) (length e))) nil))
> >
> > when i try to run it it returns an error - "listp, w".  Can anyone tell
> > me of the errors in my code and why w has to be a list when I'm using
> > string-processing "tools".
> 
> - The other reply handled most of your questions. For this particular
> piece, it seems to run OK in a Common Lisp when called with strings
> instead of symbols.
> 
> - All this reverse/subseq stuff seems superfluous, this seems to work,
> too:
> 
> (defun suffix-match2 (e w)
>     (if (string=  w e :start1 (- (length w) (length e)))
>         (subseq w 0 (- (length w) (length e)))
>       nil))

If the given word ends with the given suffix,
return the word without the suffix.

Otherwise, return false.

Ruby:

def suffix_match ending, word
  word.end_with?(ending) and word.chomp ending
end

suffix_match "ing", "acting"
    ==>"act"
suffix_match "ing", "acts"
    ==>false
suffix_match "ed", "acted"
    ==>"act"

In Forth?


-- 
Jews totally run Hollywood....  But I don't care if Americans think we're
running the news media, Hollywood, Wall Street, or the government.  I just care
that we get to keep running them. --- Joel Stein
articles.latimes.com/2008/dec/19/opinion/oe-stein19
archive.org/download/DavidDukeTv/DoJewsControlTheMediaTheLaTimesSaysYes.flv

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


Thread

:Re: confused newbie (in asbestos Y-fronts...) "Robert L." <No_spamming@noWhere_7073.org> - 2017-01-03 17:14 +0000

csiph-web