Any nice way of replacing substrings, i'm currently using below
it works but it's discusting :
(defun substring-replace (new old text )
(let ((res "") (now 0)
(old-length (length old))
(text-length (length text)))
(loop
(if (> (+ now old-length) text-length)
(progn
(if (< now text-length)
(setq res
(concatenate 'string res
(subseq text now))))
(return res))
(if (string= old
(subseq text now (+ now old-length)))
(progn
(setq res
(concatenate 'string res new))
(incf now old-length))
(progn
(setq res
(concatenate 'string res
(subseq text now (1+ now))))
(incf now)))))))
On May 2, 8:12 am, fireblade <·················@gmail.com> wrote:
> Any nice way of replacing substrings, i'm currently using below
> it works but it's discusting :
I use cl-ppcre:
(cl-ppcre:regex-replace-all old text new)
Not only is this great for substring replacement but you can use
regexs as well.
On May 2, 2:34 pm, byronsalty <··········@gmail.com> wrote:
> On May 2, 8:12 am, fireblade <·················@gmail.com> wrote:
>
> > Any nice way of replacing substrings, i'm currently using below
> > it works but it's discusting :
>
> I use cl-ppcre:
> (cl-ppcre:regex-replace-all old text new)
>
> Not only is this great for substring replacement but you can use
> regexs as well.
I'll try that thanks.
One more question, I have an application consisted of three parts ,
main-frame the staff at the top page that is same for every page in
the app, left-menu , navigation part that depends where in the app
you are and central area the meat specific for every page something
that chages a lot. So i take the string from main-frame, find marker
··@#$%"and insert the html from left-menu and central-area with
substring-replace, this looks very ugly to me Turing machine staff.
I want to make a tutorial from my application demo with hunchentoot,
cl-who & clsql and I don't want to propagate bad practices.
(defun page ()
(substring-replace
(concatenate 'string (left-menu) (central-area)) ··@#$%"
(main-frame)))
(defun main-frame ()
(with-html-output-to-string (*standard-output* nil)
(:html
(:head (:title "template"))
(:body
(:table :border 4 :cellpadding 0 :cellspacing 0 :cellpadding
0 :cols 1 :width "950"
(:tr (:td (:img :src "/hunchentoot/neo/logo.jpg" :height
106 :width 950)))
(:tr :valign "top"
(:td :align "right" :valign "top"
(dotimes (e 7)
(htm
(:right (:img :src "/hunchentoot/neo/
button.jpg" :height 33 :width 135))))))
(:tr :valign "top"
(:td :valign "top"
(:left
(:table :border 1 :CELLSPACING 4 :CELLPADDING 4 :COLS
2 :WIDTH "100%"
(:tr :valign "top" ··@#$%"))))))))))
(defun left-menu ()
(with-html-output-to-string (*standard-output* nil)
(:td :valign "top" :width "130"
(:img :src "/hunchentoot/neo/bar.jpg" :height 12 :width "100%"
(:left
(:table :border 0 :cellspacing 4 :cellpadding 4
(:tr (:td (:a :href "/hunchentoot/neo/diary-frame.html"
"diary")))
(:tr (:td (:a :href "/hunchentoot/neo/admin-frame.html"
"admin")))))))))
(defun central-area ()
(with-html-output-to-string (*standard-output* nil)
(:td
(:left
(:font :face "Verdana"
(:font :color "#000099F"
(:font :size -1
(:b "Neo"))))))))
fireblade <·················@gmail.com> writes:
> On May 2, 2:34 pm, byronsalty <··········@gmail.com> wrote:
>> On May 2, 8:12 am, fireblade <·················@gmail.com> wrote:
>>
>> > Any nice way of replacing substrings, i'm currently using below
>> > it works but it's discusting :
>>
>> I use cl-ppcre:
>> (cl-ppcre:regex-replace-all old text new)
>>
>> Not only is this great for substring replacement but you can use
>> regexs as well.
> I'll try that thanks.
>
> One more question, I have an application consisted of three parts ,
You'd better start a new threads. People uninterested in substring
replacements will have killed this thread and won't have an
opportunity to answer to your new question.
> main-frame the staff at the top page that is same for every page in
> the app, left-menu , navigation part that depends where in the app
> you are and central area the meat specific for every page something
> that chages a lot. So i take the string from main-frame, find marker
> ··@#$%"and insert the html from left-menu and central-area with
> substring-replace, this looks very ugly to me Turing machine staff.
> I want to make a tutorial from my application demo with hunchentoot,
> cl-who & clsql and I don't want to propagate bad practices.
I would write it as:
(defun main-frame ()
(with-page
(vertically
(top-of-page)
(horizontally
(left-menu)
(central-area)
(right-column))
(bottom-of-page))))
That is, instead of generating wrong data, and then correcting it, I'd
use a higher level language, and generate directly the right data in
the right place.
--
__Pascal Bourguignon__ http://www.informatimago.com/
The world will now reboot. don't bother saving your artefacts.
(message (Hello 'fireblade)
(you :wrote :on '(2 May 2007 06:29:23 -0700))
(
f> One more question, I have an application consisted of three parts ,
f> main-frame the staff at the top page that is same for every page in
f> the app, left-menu , navigation part that depends where in the app
f> you are and central area the meat specific for every page something
f> that chages a lot. So i take the string from main-frame, find marker
f> ··@#$%"and insert the html from left-menu and central-area with
f> substring-replace, this looks very ugly to me Turing machine staff.
f> I want to make a tutorial from my application demo with hunchentoot,
f> cl-who & clsql and I don't want to propagate bad practices.
what prevents you to call (left-menu) and (central-area) in place of that
ugly marker?
i'm not familiar with cl-who, but it works very well in LML[2].
you should establish html stream with "(with-html-output*" only once, then
in central-area and left-menu just use "(htm" macro to enter html generation
mode -- this works because with-html-output use not lexical but dynamic
binding.
)
(With-best-regards '(Alex Mizrahi) :aka 'killer_storm)
"I am everything you want and I am everything you need")
On May 2, 3:29 pm, fireblade <·················@gmail.com> wrote:
> On May 2, 2:34 pm, byronsalty <··········@gmail.com> wrote:> On May 2, 8:12 am, fireblade <·················@gmail.com> wrote:
> I want to make a tutorial from my application demo with hunchentoot,
> cl-who & clsql and I don't want to propagate bad practices.
Is it Ok to post the source code untill you finish the tutorial?
JT
On May 3, 10:06 am, ·············@gmail.com wrote:
> On May 2, 3:29 pm, fireblade <·················@gmail.com> wrote:
>
> > On May 2, 2:34 pm, byronsalty <··········@gmail.com> wrote:> On May 2, 8:12 am, fireblade <·················@gmail.com> wrote:
> > I want to make a tutorial from my application demo with hunchentoot,
> > cl-who & clsql and I don't want to propagate bad practices.
>
> Is it Ok to post the source code untill you finish the tutorial?
>
> JT
I'll mail it to you.Is your google group address real?
cheers
bobi
On May 2, 2:53 pm, ······@gmail.com wrote:
> On May 2, 3:12 pm, fireblade <·················@gmail.com> wrote:
>
> > Any nice way of replacing substrings, i'm currently using below
>
> clhs replace?
That's different thing completely, substring-replace works like this:
(substring-replace "cat" "dog" "dog ate my homework. A big dog")
=>"cat ate my homework. A big cat"
cheers
bobi
On 2 May 2007 05:53:33 -0700, ······@gmail.com wrote:
> On May 2, 3:12 pm, fireblade <·················@gmail.com> wrote:
>> Any nice way of replacing substrings, i'm currently using below
>
> clhs replace?
Did you even look at the code the OP posted? CL's REPLACE has
completely different semantics.
--
Lisp is not dead, it just smells funny.
Real email: (replace (subseq ·········@agharta.de" 5) "edi")