[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Re: photo album in chicken

From: Ashish Shrestha
Subject: Re: [Chicken-users] Re: photo album in chicken
Date: Sun, 30 Apr 2006 21:54:40 +0100

Thank you Kon, Reed and Peter for the feedback.

Editing scheme code:
Yes, I am hand-indenting and most probably don't have the indenting
correct. I did try emacs but went back to vi/vim because of two

First, vi/vim is available in most Linux (I use gentoo on my server)
and Mac OSX (my personal laptop). It doesn't require additional
installation. I have installed it with cygwin on my work machine.

Second reason, most of the people I know use vi and hence I keep
learning new things. I did give emacs a try but I didn't really find
myself very productive in it. I guess I haven't really seen some one
use emacs regularly to understand it.

I think auto-destroy of garbage images would be really nice. When
working in scheme you definitely forget managing resources. May be if
it were C I would think of imlib:destroy but with scheme it never
occured to me that I might need to do that. I just thought it would be
marked as garbage and collected when the image was out of scope.

The code definitely shows I haven't learnt to think in scheme yet :) I
want to write a few practical applications with scheme before going
back to reading some of the scheme books. I am trying not to write
Python or Java with Scheme's synatx. I think when I see a problem I am
still breaking it down in my head in terms of how I would solve it in
Java or Python. Hopefully, more code like this will help me see

A quick question, what is the recommended/standard way to handle
exceptions/errors. For example, if you have an IO error?

This exercise had definitely been a very useful learning experience for me.


On 4/30/06, Kon Lovett <address@hidden> wrote:

On Apr 30, 2006, at 9:44 AM, Reed Sheridan wrote:

> From: "Ashish Shrestha" <address@hidden >
> Subject: [Chicken-users] photo album in chicken
> To: address@hidden
> Message-ID:
>         <
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Also, here is a more schemely and more compact normalise-path function:

(define (rps-normalise-path path)
  (let loop ((reverse-parts (reverse (string-split path "/")))
         (skip 0)
         (acc '()))
    (match reverse-parts
      (() (string-join acc "/"))
      (("." . more) (loop more skip acc))
      ((".." . more) (loop more (add1 skip) acc))
      ((path-part . more)
         (if (zero? skip)
             (loop more 0 (cons path-part acc))
             (loop more (sub1 skip) acc))))))

This version handles paths with "../../", but drops the leading "/" from
absolute paths (so did yours).

Prefer your over my offering. (Would just stripping the current-directory
elements be useful separately? Thought it might be so broke it out for later
top-level define, but ...)

(define (pathname-normalize path)
  (let loop ([parts (reverse! (string-split path "/"))] [skip 0] [acc '()])
    (match parts
      (() (string-join (or (and (absolute-pathname? path) (cons "" acc))
acc) "/"))
      (("." . more) (loop more skip acc))
      ((".." . more) (loop more (add1 skip) acc))
      ((path-part . more)
         (if (zero? skip)
 (loop more 0 (cons path-part acc))
 (loop more (sub1 skip) acc))))))

Best Wishes,

Chicken-users mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]