[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Create a textbox in Lisp

gengyangcai

8/12/2015 12:27:00 AM

I want to create a text box on a page that says "Lisp is a powerful language". It should look like this :


----------------------------------
| |
| Lisp is a powerful language |
| |
| |
----------------------------------


How do it do this ?

Thanks alot !

Cai GengYang
caigy84@gmail.com
6 Answers

Pascal J. Bourguignon

8/12/2015 1:11:00 AM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> I want to create a text box on a page that says "Lisp is a powerful language". It should look like this :
>
> ----------------------------------
> | |
> | Lisp is a powerful language |
> | |
> | |
> ----------------------------------


cl-user> (let ((message "Lisp is a powerful language"))
(format t "+--~V,,,'-<~>--+~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*+--~V,,,'-<~>--+~%"
(length message) message))
+-------------------------------+
| |
| Lisp is a powerful language |
| |
| |
+-------------------------------+
nil
cl-user>

Oops, sorry, there's a bug here.


There you go:

cl-user> (let ((message "Lisp is a powerful language"))
(format t "----~V,,,'-<~>---~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*----~V,,,'-<~>---~%"
(length message) message))
----------------------------------
| |
| Lisp is a powerful language |
| |
| |
----------------------------------
nil
cl-user>

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Mark Simpson

8/12/2015 1:55:00 AM

0

>>>>> On Wed, 12 Aug 2015 03:11:08 +0200, "Pascal J. Bourguignon" <pjb@informatimago.com> said:

Pascal> CAI GENGYANG <gengyangcai@gmail.com> writes:

>> I want to create a text box on a page that says "Lisp is a
>> powerful language". It should look like this :
>>
>> ----------------------------------
>> | |
>> | Lisp is a powerful language |
>> | |
>> | |
>> ----------------------------------


cl-user> (let ((message "Lisp is a powerful language"))
Pascal> (format t "----~V,,,'-<~>---~%~:*| ~V<~> |~%| ~A |~%~0@*|
Pascal> ~V<~> |~%~:*| ~V<~> |~%~:*----~V,,,'-<~>---~%" (length
Pascal> message) message)) ----------------------------------
Pascal> | |
Pascal> | Lisp is a powerful language |
Pascal> | |
Pascal> | |
Pascal> ---------------------------------- nil
cl-user>


FORMAT is such crazy magic, I love it.

(Also points for implementing exactly according to the specification.)

Frank GOENNINGER

8/12/2015 5:59:00 AM

0


"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

> CAI GENGYANG <gengyangcai@gmail.com> writes:
>
>> I want to create a text box on a page that says "Lisp is a powerful
>> language". It should look like this :
>>
>> ----------------------------------
>> | |
>> | Lisp is a powerful language |
>> | |
>> | |
>> ----------------------------------

At this point I thought: "Oh no - she still didn't get it!"


> cl-user> (let ((message "Lisp is a powerful language"))
> (format t "+--~V,,,'-<~>--+~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*+--~V,,,'-<~>--+~%"
> (length message) message))
> +-------------------------------+
> | |
> | Lisp is a powerful language |
> | |
> | |
> +-------------------------------+
> nil
> cl-user>
>
> Oops, sorry, there's a bug here.
>
>
> There you go:
>
> cl-user> (let ((message "Lisp is a powerful language"))
> (format t "----~V,,,'-<~>---~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*----~V,,,'-<~>---~%"
> (length message) message))
> ----------------------------------
> | |
> | Lisp is a powerful language |
> | |
> | |
> ----------------------------------
> nil
> cl-user>

At this point I had to explain to my wife why on earth I'm screaming
laughing...

Logged here as a classic "I can't describe what I want but I get it
exactly that way" - or why real consultants don't deliver what the
client wants but what the client needs.

+1, too, for the use of format to solve this puzzle!

;; Frank

Marco Antoniotti

8/12/2015 7:42:00 AM

0

On Wednesday, August 12, 2015 at 8:59:24 AM UTC+3, Frank DG1SBG wrote:
> "Pascal J. Bourguignon" <pjb@informatimago.com> writes:
>
> > CAI GENGYANG <gengyangcai@gmail.com> writes:
> >
> >> I want to create a text box on a page that says "Lisp is a powerful
> >> language". It should look like this :
> >>
> >> ----------------------------------
> >> | |
> >> | Lisp is a powerful language |
> >> | |
> >> | |
> >> ----------------------------------
>
> At this point I thought: "Oh no - she still didn't get it!"
>
>
> > cl-user> (let ((message "Lisp is a powerful language"))
> > (format t "+--~V,,,'-<~>--+~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*+--~V,,,'-<~>--+~%"
> > (length message) message))
> > +-------------------------------+
> > | |
> > | Lisp is a powerful language |
> > | |
> > | |
> > +-------------------------------+
> > nil
> > cl-user>
> >
> > Oops, sorry, there's a bug here.
> >
> >
> > There you go:
> >
> > cl-user> (let ((message "Lisp is a powerful language"))
> > (format t "----~V,,,'-<~>---~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*----~V,,,'-<~>---~%"
> > (length message) message))
> > ----------------------------------
> > | |
> > | Lisp is a powerful language |
> > | |
> > | |
> > ----------------------------------
> > nil
> > cl-user>
>
> At this point I had to explain to my wife why on earth I'm screaming
> laughing...
>
> Logged here as a classic "I can't describe what I want but I get it
> exactly that way" - or why real consultants don't deliver what the
> client wants but what the client needs.
>
> +1, too, for the use of format to solve this puzzle!
>
> ;; Frank

Ok, guys. You had your fun :)

In Lispworks

(capi:display-message "Lisp is such a powerful language")

or

(capi:contain (make-instance :text "Lisp is such a powerful language"))

Or

(with-open-file (f "index.html" :direction :output)
(<:with-html-syntax-output (f :print-pretty t)
(<:document ()
(<:h1 () "Lisp")
(<:p () "... is such a pretty tasty soup of toenails clippings!")))

Of course... using the XHTMLambda library :)

Cheers
--
MA

William James

8/12/2015 9:05:00 AM

0

Pascal J. Bourguignon wrote:

> > I want to create a text box on a page that
> > says "Lisp is a powerful language". It
> > should look like this :
> >
> >
> > ----------------------------------
> > | |
> > | Lisp is a powerful language |
> > | |
> > | |
> > ----------------------------------
>
>
> cl-user> (let ((message "Lisp is a powerful language"))
> (format t "+--~V,,,'-<~>--+~%~:*| ~V<~> |~%| ~A
> |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*+--~V,,,'-<~>--+~%"
> (length message) message))
> +-------------------------------+
> | |
> | Lisp is a powerful language |
> | |
> | |
> +-------------------------------+


Gauche Scheme:

(define (box-line width fill-chr wrap-str text)
(let1 pad (make-string (ceiling (/ (- width (string-length text)) 2)) fill-chr)
(string-append wrap-str
(string-copy (string-append pad text pad) 0 width)
wrap-str)))

(define (box . lines)
(let* ((size (+ 4 (apply max (map string-length lines))))
(wrapper (box-line size #\- "+" ""))
(blank (box-line size #\space "|" "")))
(for-each print
`(,wrapper ,blank ,@(map (pa$ box-line size #\space "|") lines)
,blank ,wrapper))))

(box "CL is not Lisp." "As Graham said,"
"it's not Lisp that sucks," "but CL.")

+-----------------------------+
| |
| CL is not Lisp. |
| As Graham said, |
| it's not Lisp that sucks, |
| but CL. |
| |
+-----------------------------+


--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot

gengyangcai

8/18/2015 10:49:00 AM

0

On Wednesday, August 12, 2015 at 9:11:18 AM UTC+8, informatimago wrote:
> CAI GENGYANG <gengyangcai@gmail.com> writes:
>
> > I want to create a text box on a page that says "Lisp is a powerful language". It should look like this :
> >
> > ----------------------------------
> > | |
> > | Lisp is a powerful language |
> > | |
> > | |
> > ----------------------------------
>
>
> cl-user> (let ((message "Lisp is a powerful language"))
> (format t "+--~V,,,'-<~>--+~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*+--~V,,,'-<~>--+~%"
> (length message) message))
> +-------------------------------+
> | |
> | Lisp is a powerful language |
> | |
> | |
> +-------------------------------+
> nil
> cl-user>
>
> Oops, sorry, there's a bug here.
>
>
> There you go:
>
> cl-user> (let ((message "Lisp is a powerful language"))
> (format t "----~V,,,'-<~>---~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*----~V,,,'-<~>---~%"
> (length message) message))
> ----------------------------------
> | |
> | Lisp is a powerful language |
> | |
> | |
> ----------------------------------
> nil
> cl-user>
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk



Yup, it works ...

CL-USER 4 > (let ((message "Lisp is a powerful language"))
(format t "+--~V,,,'-<~>--+~%~:*| ~V<~> |~%| ~A |~%~0@*| ~V<~> |~%~:*| ~V<~> |~%~:*+--~V,,,'-<~>--+~%"
(length message) message))
+-------------------------------+
| |
| Lisp is a powerful language |
| |
| |
+-------------------------------+
NIL