after i post i thought to do this. it seems to work.
sorry more for random postings. i am excited about
my code. anyway, please criticize and help me improve.
thanks, david
(defun legal-position()
(let* ((lst (get-positions))
(wk (rank-file (cdr (assoc 'wk lst))))
(bk (rank-file (cdr (assoc 'bk lst)))))
(if (not (member (reverse-rank-file bk)
(mapcar #'reverse-rank-file (bad-squares wk))))
lst (legal-position))))
From: Pascal J. Bourguignon
Subject: Re: my functions works (i think), now i am stuck
Date:
Message-ID: <87prh049dj.fsf@galatea.local>
david <······@gmail.com> writes:
> hello lispers. sorry for all my random posts today.
> i have a function legal-position which either returns a legal
> chess position or nil. i hope. now i would like to do
> something like call my function and if it returns nil
> have it run until it return a legal position. please help
> me cll, you're my only hope.
> thanks in advance, david
(loop :until (your-function))
If you wanted to return the last value returned by your-function:
(loop :for result = (your-function) :until result :finally (return result))
Notice that (if (f) (loop :until (f))) is equivalent to (loop :until (f))
(This means that you can implement IF with conditional loops).
--
__Pascal Bourguignon__
From: William James
Subject: Re: my functions works (i think), now i am stuck
Date:
Message-ID: <gogsjt09vm@enews4.newsguy.com>
Pascal J. Bourguignon wrote:
> If you wanted to return the last value returned by your-function:
>
> (loop :for result = (your-function) :until result :finally (return
> result))
Clojure:
; An example function for testing purposes.
(defn foo [] (let [r (rand)] (if (> r 0.9) r false)))
(take 1 (filter (fn [x] x) (repeatedly foo)))
From: William James
Subject: Re: my functions works (i think), now i am stuck
Date:
Message-ID: <gogspt0a3v@enews4.newsguy.com>
William James wrote:
> Pascal J. Bourguignon wrote:
>
> > If you wanted to return the last value returned by your-function:
> >
> > (loop :for result = (your-function) :until result :finally (return
> > result))
>
> Clojure:
>
> ; An example function for testing purposes.
> (defn foo [] (let [r (rand)] (if (> r 0.9) r false)))
>
>
> (take 1 (filter (fn [x] x) (repeatedly foo)))
Make that
(first (filter (fn [x] x) (repeatedly foo)))
On 2 Mar, 16:08, "William James" <> wrote:
> William James wrote:
> > Pascal J. Bourguignon wrote:
>
> > > If you wanted to return the last value returned by your-function:
>
> > > (loop :for result = (your-function) :until result :finally (return
> > > result))
>
> > Clojure:
>
> > ; An example function for testing purposes.
> > (defn foo [] (let [r (rand)] (if (> r 0.9) r false)))
>
> > (take 1 (filter (fn [x] x) (repeatedly foo)))
>
> Make that
>
> (first (filter (fn [x] x) (repeatedly foo)))
(1) It ain't Ruby, (2) it ain't F#. But it is (almost) Coming
Lisp. :)
Cheers
--
Marco
From: =?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=
Subject: Re: my functions works (i think), now i am stuck
Date:
Message-ID: <govc90$1al$1@news.motzarella.org>
William James schrieb:
> William James wrote:
>
>> Pascal J. Bourguignon wrote:
>>
>>> If you wanted to return the last value returned by your-function:
>>>
>>> (loop :for result = (your-function) :until result :finally (return
>>> result))
>> Clojure:
>>
>> ; An example function for testing purposes.
>> (defn foo [] (let [r (rand)] (if (> r 0.9) r false)))
>>
>>
>> (take 1 (filter (fn [x] x) (repeatedly foo)))
>
> Make that
>
> (first (filter (fn [x] x) (repeatedly foo)))
Good good, you already made that correction of replacing (take 1) with
(first).
But I would suggest to use identity:
(first (filter identity (repeateyly foo)))
I don’t care that it saves to chars. Even if it wouldn’t: I find it
clearer to reuse an existing function. If I was after the charcount then
maybe (first (filter #(do %) (repeatedly foo))) would be a good solution.
André
--
Lisp is not dead. It’s just the URL that has changed:
http://clojure.org/
From: William James
Subject: Re: my functions works (i think), now i am stuck
Date:
Message-ID: <gp06p402998@enews2.newsguy.com>
William James wrote:
> William James wrote:
>
> > Pascal J. Bourguignon wrote:
> >
> > > If you wanted to return the last value returned by your-function:
> > >
> > > (loop :for result = (your-function) :until result :finally (return
> > > result))
> >
> > Clojure:
> >
> > ; An example function for testing purposes.
> > (defn foo [] (let [r (rand)] (if (> r 0.9) r false)))
> >
> >
> > (take 1 (filter (fn [x] x) (repeatedly foo)))
>
> Make that
>
> (first (filter (fn [x] x) (repeatedly foo)))
(first (filter identity (repeatedly foo)))