Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
gethash substring
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  18 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Frode Vatvedt Fjeld  
View profile  
 More options Aug 21 2002, 9:39 am
Newsgroups: comp.lang.lisp
From: Frode Vatvedt Fjeld <fro...@acm.org>
Date: Wed, 21 Aug 2002 15:39:01 +0200
Local: Wed, Aug 21 2002 9:39 am
Subject: gethash substring
I often find that I need to look up a sub-string in a hash-table. By
"sub-string" I mean a string that starts and ends at given indexes of
another string. It goes something like this:

  (gethash (subseq <original-string> <start> <end>)
           <hash-table>)

The problem is that I can't afford to cons up a new string (as subseq
does) just for performing such look-ups.

The only solution I see to this problem, is to implement my own
hash-table. Is there a better way?

--
Frode Vatvedt Fjeld


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Johannes Grødem  
View profile  
 More options Aug 21 2002, 9:47 am
Newsgroups: comp.lang.lisp
From: "Johannes Grødem" <s...@kopkillah.com>
Date: Wed, 21 Aug 2002 15:47:10 +0200
Local: Wed, Aug 21 2002 9:47 am
Subject: Re: gethash substring
* Frode Vatvedt Fjeld <fro...@acm.org>:

> The only solution I see to this problem, is to implement my own
> hash-table. Is there a better way?

Couldn't you just allocate an array with a fill-pointer and copy into
this and use it as the key-parameter to gethash?  Or am I missing
something here?

--
johs


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frode Vatvedt Fjeld  
View profile  
 More options Aug 21 2002, 11:40 am
Newsgroups: comp.lang.lisp
From: Frode Vatvedt Fjeld <fro...@acm.org>
Date: Wed, 21 Aug 2002 17:40:06 +0200
Local: Wed, Aug 21 2002 11:40 am
Subject: Re: gethash substring

"Johannes Grødem" <s...@kopkillah.com> writes:
> Couldn't you just allocate an array with a fill-pointer and copy
> into this and use it as the key-parameter to gethash?

Yes, I could.

> Or am I missing something here?

This function wouldn't be reentrant, which might or might not be a
problem, I suppose. I'm not a functional (programming) fanatic, but
this sort of thing feels slightly non-Common-Lispian to a Patriot such
as myself.

--
Frode Vatvedt Fjeld


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Margolin  
View profile  
 More options Aug 21 2002, 11:48 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@genuity.net>
Date: Wed, 21 Aug 2002 15:25:48 GMT
Local: Wed, Aug 21 2002 11:25 am
Subject: Re: gethash substring
In article <2hbs7we3gq....@vserver.cs.uit.no>,
Frode Vatvedt Fjeld  <fro...@acm.org> wrote:

>The problem is that I can't afford to cons up a new string (as subseq
>does) just for performing such look-ups.

Why not?  If the Lisp implementation has an ephemeral GC (as many do), the
cost of short-lived objects like this is pretty small.

But the other responder's suggestion to reuse the same string is a good
one, too.  You might also search around for "resources", a way to maintain
a collection of reusable objects.

--
Barry Margolin, bar...@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pierpaolo BERNARDI  
View profile  
 More options Aug 21 2002, 11:53 am
Newsgroups: comp.lang.lisp
From: "Pierpaolo BERNARDI" <pierpaolo_berna...@hotmail.com>
Date: Wed, 21 Aug 2002 15:53:50 GMT
Local: Wed, Aug 21 2002 11:53 am
Subject: Re: gethash substring

"Frode Vatvedt Fjeld" <fro...@acm.org> ha scritto nel messaggio news:2hbs7we3gq.fsf@vserver.cs.uit.no...

> I often find that I need to look up a sub-string in a hash-table. By
> "sub-string" I mean a string that starts and ends at given indexes of
> another string. It goes something like this:

>   (gethash (subseq <original-string> <start> <end>)
>            <hash-table>)

> The problem is that I can't afford to cons up a new string (as subseq
> does) just for performing such look-ups.

> The only solution I see to this problem, is to implement my own
> hash-table. Is there a better way?

You can create _one_ displaced string and reuse
it multiple times with ADJUST-ARRAY.

(let ((substring (make-array 0 :element-type 'character
                 :displaced-to "" :displaced-index-offset 0)))
  ...

  (gethash
    (adjust-array substring (- <end> <start>)
            :displaced-to <original-string>
            :displaced-index-offset <start>)
    <hash-table>))

P.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pierpaolo BERNARDI  
View profile  
 More options Aug 21 2002, 12:01 pm
Newsgroups: comp.lang.lisp
From: "Pierpaolo BERNARDI" <pierpaolo_berna...@hotmail.com>
Date: Wed, 21 Aug 2002 16:01:40 GMT
Local: Wed, Aug 21 2002 12:01 pm
Subject: Re: gethash substring

"Frode Vatvedt Fjeld" <fro...@acm.org> ha scritto nel messaggio news:2hwuqkcjah.fsf@vserver.cs.uit.no...

> > Or am I missing something here?

> This function wouldn't be reentrant, which might or might not be a
> problem,

Yes, in a MT CL you'll have to put the copy or displacing and
table access in a critical section, unless mutual exclusion is
guaranted by some other protocol.

> I suppose. I'm not a functional (programming) fanatic, but
> this sort of thing feels slightly non-Common-Lispian to a Patriot such
> as myself.

If you are using hash-tables you are not doing functional
programming anyway.

P.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Aug 21 2002, 2:25 pm
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@cs.nyu.edu>
Date: 21 Aug 2002 14:25:27 -0400
Local: Wed, Aug 21 2002 2:25 pm
Subject: Re: gethash substring

This is a very good suggestion.  It should go in the CL Cookbook.

Cheers

--
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
715 Broadway 10th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Aug 21 2002, 6:10 pm
Newsgroups: comp.lang.lisp
From: k...@ashi.footprints.net (Kaz Kylheku)
Date: 21 Aug 2002 15:10:59 -0700
Local: Wed, Aug 21 2002 6:10 pm
Subject: Re: gethash substring
Frode Vatvedt Fjeld <fro...@acm.org> wrote in message <news:2hbs7we3gq.fsf@vserver.cs.uit.no>...

> I often find that I need to look up a sub-string in a hash-table. By
> "sub-string" I mean a string that starts and ends at given indexes of
> another string. It goes something like this:

>   (gethash (subseq <original-string> <start> <end>)
>            <hash-table>)

> The problem is that I can't afford to cons up a new string (as subseq
> does) just for performing such look-ups.

You can create a string object which shares the actual character
data with the original string, though some space is still allocated
obviously to keep track of where the substring beings and ends.
Look at the :DISPLACED-TO keyword parameter of MAKE-ARRAY.
Can you spare that much space?

  (defparameter *string1* "abcdefg")
  (defparameter *string2* (make-array '(3)
                                      :element-type 'character
                                      :displaced-to *string1*
                                      :displaced-index-offset 1))
  *string2* ==> "bcd"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Espen Vestre  
View profile  
 More options Aug 22 2002, 3:46 am
Newsgroups: comp.lang.lisp
From: Espen Vestre <espen@*do-not-spam-me*.vestre.net>
Date: Thu, 22 Aug 2002 07:46:08 GMT
Local: Thurs, Aug 22 2002 3:46 am
Subject: Re: gethash substring

"Pierpaolo BERNARDI" <pierpaolo_berna...@hotmail.com> writes:
> You can create _one_ displaced string and reuse
> it multiple times with ADJUST-ARRAY.

Good idea!

Even if you don't reuse it, using a displaced array for the substring
_sometimes_ pays off (If both the whole string and the substring
are fairly large, you may save some memory. You really need to do
tests to see how much, if anything, you gain with your implementation
of choice).
--
  (espen)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ed L Cashin  
View profile  
 More options Aug 24 2002, 10:51 pm
Newsgroups: comp.lang.lisp
From: Ed L Cashin <ecas...@uga.edu>
Date: 24 Aug 2002 22:49:18 -0400
Local: Sat, Aug 24 2002 10:49 pm
Subject: Re: gethash substring

Why not?  Could you elaborate?  If functions can return numbers then
why not hash tables?

--
--Ed L Cashin            |   PGP public key:
  ecas...@uga.edu        |   http://noserose.net/e/pgp/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Aug 24 2002, 11:04 pm
Newsgroups: comp.lang.lisp
From: Erik Naggum <e...@naggum.no>
Date: 25 Aug 2002 03:04:12 +0000
Local: Sat, Aug 24 2002 11:04 pm
Subject: Re: gethash substring
* Pierpaolo BERNARDI
| If you are using hash-tables you are not doing functional programming
| anyway.

* Ed L Cashin
| Why not?  Could you elaborate?  If functions can return numbers then
| why not hash tables?

  The hash table operations do not return a new hashtable with the specified
  changes made and retain the old value.  Quite contrary, the whole point is
  to modify the state of an existing object.  This is a side effect and is not
  thus sufficiently functional.  (When functional programming languages
  support I/O, I see little point in arguing about such things, as they have
  already proved that at least the side effect of changing the state of some
  I/O stream is allowable, but for some reason, the functional programming
  paradigm has not been shot down as fundamentally silly in its excesses.)

--
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen J. Bevan  
View profile  
 More options Aug 25 2002, 1:43 am
Newsgroups: comp.lang.lisp
From: step...@dino.dnsalias.com (Stephen J. Bevan)
Date: Sun, 25 Aug 2002 05:35:17 GMT
Local: Sun, Aug 25 2002 1:35 am
Subject: Re: gethash substring

Erik Naggum <e...@naggum.no> writes:
>   thus sufficiently functional.  (When functional programming languages
>   support I/O, I see little point in arguing about such things, as they have
>   already proved that at least the side effect of changing the state of some
>   I/O stream is allowable, but for some reason, the functional programming
>   paradigm has not been shot down as fundamentally silly in its excesses.)

Leaving aside whether it is fundamentally silly, Haskell and Clean
have I/O but they do not work by allowing a change of state of an I/O
stream.  Instead the type system ensures that the stream is only used
in a single threaded manner (either via monads in Haskell or unique
types in Clean) so that the "side-effect" isn't a side-effect at all,
it is a direct effect and is clear from the type of any I/O function.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "I/O in pure functional languages (Re: gethash substring)" by Kalle Olavi Niemitalo
Kalle Olavi Niemitalo  
View profile  
 More options Aug 25 2002, 5:51 am
Newsgroups: comp.lang.lisp
From: Kalle Olavi Niemitalo <k...@iki.fi>
Date: 25 Aug 2002 12:32:58 +0300
Local: Sun, Aug 25 2002 5:32 am
Subject: I/O in pure functional languages (Re: gethash substring)
step...@dino.dnsalias.com (Stephen J. Bevan) writes:

> Instead the type system ensures that the stream is only used
> in a single threaded manner (either via monads in Haskell or unique
> types in Clean) so that the "side-effect" isn't a side-effect at all,
> it is a direct effect and is clear from the type of any I/O function.

Does this mean any function that writes to a log file must take
the original file as a parameter and return the modified file?
And the same with anything that calls it.

Do they have an equivalent to the Unix98 pread function, which
does not change the file offset?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen J. Bevan  
View profile  
 More options Aug 25 2002, 11:29 am
Newsgroups: comp.lang.lisp
From: step...@dino.dnsalias.com (Stephen J. Bevan)
Date: Sun, 25 Aug 2002 15:29:35 GMT
Local: Sun, Aug 25 2002 11:29 am
Subject: Re: I/O in pure functional languages (Re: gethash substring)
Kalle Olavi Niemitalo <k...@iki.fi> writes:

> Does this mean any function that writes to a log file must take
> the original file as a parameter and return the modified file?
> And the same with anything that calls it.

We might have different ideas about what it means to "take the
original file as a parameter" so I'll answer by showing the types of
the functions in Haskell that would be used to open a file and write a
String to the file :-

  openFile  :: FilePath -> IOMode -> IO Handle
  hPutStrLn :: Handle -> String -> IO ()

Here the IO type is the important one since this ensures that I/O is
single threaded and represented in the types so that it is not
possible to hide I/O inside a function which doesn't have IO in its
type signature (note I'm not arguing whether this is good or bad, just
noting that I/O is not a side-effect).  In Clean instead of using the
(monadic) IO type, unique types are used to ensure that functions
which take the "world" as an argument use that argument in a linear
manner thereby ensuring that I/O is not a side effect but an a direct
effect.

> Do they have an equivalent to the Unix98 pread function, which
> does not change the file offset?

Haskell does not.  You can look at the I/O library yourself at
http://www.haskell.org/onlinelibrary/io.html.  The Clean approach
using unique types is briefly described in
http://www.cs.kun.nl/~clean/CleanExtra/report20/chapter2/s23.html#s231b
An overview of the I/O system (including some screen shots of games produced
using it) are available at :-
http://www.cs.kun.nl/~clean/About_Clean/page_modified/page_modified.html
and the full gory details of the Clean I/O library are available at
ftp://ftp.cs.kun.nl/pub/Clean/supported/ObjectIO.1.2/doc/tutorial.ps.gz

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Aug 25 2002, 1:44 pm
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@ashi.footprints.net>
Date: Sun, 25 Aug 2002 17:44:32 +0000 (UTC)
Local: Sun, Aug 25 2002 1:44 pm
Subject: Re: I/O in pure functional languages (Re: gethash substring)

In article <m3vg5zgdpr....@dino.dnsalias.com>, Stephen J. Bevan wrote:
> We might have different ideas about what it means to "take the
> original file as a parameter" so I'll answer by showing the types of
> the functions in Haskell that would be used to open a file and write a
> String to the file :-

>   openFile  :: FilePath -> IOMode -> IO Handle
>   hPutStrLn :: Handle -> String -> IO ()

> Here the IO type is the important one since this ensures that I/O is
> single threaded and represented in the types so that it is not
> possible to hide I/O inside a function which doesn't have IO in its
> type signature (note I'm not arguing whether this is good or bad, just
> noting that I/O is not a side-effect).

If output to a file is not a side-effect, then it must necessarily work by
consing up a fresh computer that is a copy of the previous one, except that
some bits are changed on the hard drive. That way any parts of the system
that have a reference to the old computer don't notice anything. :)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen J. Bevan  
View profile  
 More options Aug 25 2002, 11:45 pm
Newsgroups: comp.lang.lisp
From: step...@dino.dnsalias.com (Stephen J. Bevan)
Date: Mon, 26 Aug 2002 03:25:47 GMT
Local: Sun, Aug 25 2002 11:25 pm
Subject: Re: I/O in pure functional languages (Re: gethash substring)

Kaz Kylheku <k...@ashi.footprints.net> writes:
> If output to a file is not a side-effect, then it must necessarily work by
> consing up a fresh computer that is a copy of the previous one, except that
> some bits are changed on the hard drive. That way any parts of the system
> that have a reference to the old computer don't notice anything. :)

You are thinking too small, the Clean argument that ensures
single-threaded behaviour isn't typically called "world" for nothing :-)

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kent M Pitman  
View profile  
 More options Aug 26 2002, 12:18 pm
Newsgroups: comp.lang.lisp
From: Kent M Pitman <pit...@world.std.com>
Date: Mon, 26 Aug 2002 16:14:48 GMT
Local: Mon, Aug 26 2002 12:14 pm
Subject: Re: I/O in pure functional languages (Re: gethash substring)
Kalle Olavi Niemitalo <k...@iki.fi> writes:

> step...@dino.dnsalias.com (Stephen J. Bevan) writes:

> > Instead the type system ensures that the stream is only used
> > in a single threaded manner (either via monads in Haskell or unique
> > types in Clean) so that the "side-effect" isn't a side-effect at all,
> > it is a direct effect and is clear from the type of any I/O function.

> Does this mean any function that writes to a log file must take
> the original file as a parameter and return the modified file?
> And the same with anything that calls it.

> Do they have an equivalent to the Unix98 pread function, which
> does not change the file offset?

No, you get back a whole new file system that has the output done.

This should have been obvious.  Think about delete-file.

;)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Aug 27 2002, 3:02 am
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@ashi.footprints.net>
Date: Tue, 27 Aug 2002 07:02:30 +0000 (UTC)
Local: Tues, Aug 27 2002 3:02 am
Subject: Re: I/O in pure functional languages (Re: gethash substring)

In article <m3elcmgv4k....@dino.dnsalias.com>, Stephen J. Bevan wrote:
> Kaz Kylheku <k...@ashi.footprints.net> writes:
>> If output to a file is not a side-effect, then it must necessarily work by
>> consing up a fresh computer that is a copy of the previous one, except that
>> some bits are changed on the hard drive. That way any parts of the system
>> that have a reference to the old computer don't notice anything. :)

> You are thinking too small, the Clean argument that ensures
> single-threaded behaviour isn't typically called "world" for nothing :-)

Maybe quantum computing will rescue these pure programmers, assuming that the
parallel-worlds interpretation is valid.

When you change the state of the computer at all, you cons up a new reality
that proceeds in parallel with the old one.

Garbage collection can be done by collapsing wave functions.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »