[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.lisp

oh, 15% default for tip. was Learning Lisp: Now Stumped.

Richard Fateman

12/26/2015 6:25:00 PM

(defun tipper(bill &optional(percent 15))
(if (< percent 0) "no negative tips please"
(* bill (1+ (* percent 0.01)) )))
14 Answers

Pascal J. Bourguignon

12/26/2015 7:35:00 PM

0

Richard Fateman <fateman@cs.berkeley.edu> writes:

> (defun tipper(bill &optional(percent 15))
> (if (< percent 0) "no negative tips please"
> (* bill (1+ (* percent 0.01)) )))

See, this is what I mean.

Lisp would be used to define domain specific languages.

Of course, a lisper would use just such a function to compute his tips,
and use the REPL and the lisp debugger:

cl-user> (defun tipper (bill &optional (percent 15))
(check-type bill (real 0))
(check-type percent (real 0))
(* bill (1+ (* percent 0.01))))
tipper
cl-user> (tipper 32.25 12)
36.12
cl-user> (tipper 32.25)
37.087498
cl-user> (tipper -32.25)
Invoking restart: Assign a new value of type (real 0) to bill
New value for bill :32.25

37.087498
cl-user>

But here we use list to provide a user interface for non-lispers, and
doing this by defining DSL-like abstractions.

Things like ORP and POSITIVE-REAL-P are parts of a predicate DSL.

Things like input-and-validate-field are parts of a user interface DSL.

Those mini-DSL are combined with lisp in tip-calculator to provide the
friendly user experience.

--
__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

Richard Fateman

12/26/2015 10:33:00 PM

0


>
> But here we use list to provide a user interface for non-lispers.

Well, there are so many things that could go wrong that you are not
able to check for. Like if the user does not terminate a line, or uses
a tab. Doesn't a tab go to the next field? Why does it not respond
to voice input like Siri?
What if the bill amount was equal to most-positive-double-float,and
the calculation overflowed?
What if the user was in certain European countries and insisted on using
a comma rather than a decimal point.

If you want to learn lisp, do you need to start with a GUI toolkit that
allows the user to click on a button and pop up a numeric keyboard to
enter a top percentage? Sure you can find an interactive programming
environment in Lisps with GUI toolkits, but is that how to begin?

This person was supposedly "learning lisp", not PHP or Ruby or some
language in which all computations are done with a database system
in the cloud.


Is there really some tutorial lisp book expecting that a beginning lisp
learner should write a program to read a line of text and parse floating
point numbers explicitly from it?




Dimitri Fontaine

12/27/2015 12:06:00 AM

0

Richard Fateman <fateman@cs.berkeley.edu> writes:
> If you want to learn lisp, do you need to start with a GUI toolkit that
> allows the user to click on a button and pop up a numeric keyboard to
> enter a top percentage? Sure you can find an interactive programming
> environment in Lisps with GUI toolkits, but is that how to begin?

Given the current default assumptions of people new enough to
programming that they would consider this exercise as a challenge, I
guess we need to start with a web-based GUI, yes.

A single-page web application with a responsive form in HTML and enough
metadata that the numeric keyboard is auto-selected on handled devices
sounds like the minimum viable GUI nowadays, I would venture.

In term of Common Lisp I guess it translates to a web-server that would
contain the application in a specific route, and could contain many such
small interactive toy (then real) applications.

I have been using hunchentoot and a hacked version of simple-routes to
do that in the past, with buildapp to produce a self-contained binary
image, and some more to handle the Unix-like CLI commands one would
expect (start, stop, restart, pid, reload, etc).

See pgcharts for an example of such a self-contained web application:

https://github.com/dimitr...

Maybe â??weâ? could work on a simple kit where it's easy for newcomers to
add some simple static HTML for the UI and the very simple lisp code for
the â??backendâ?, and some routing in between those, and all the remaining
boring details would be provided for already?

Regards,
--
dim

Richard Fateman

12/27/2015 12:42:00 AM

0

On 12/26/2015 4:05 PM, Dimitri Fontaine wrote:
> Richard Fateman <fateman@cs.berkeley.edu> writes:
>> If you want to learn lisp, do you need to start with a GUI toolkit that
>> allows the user to click on a button and pop up a numeric keyboard to
>> enter a top percentage? Sure you can find an interactive programming
>> environment in Lisps with GUI toolkits, but is that how to begin?
>
> Given the current default assumptions of people new enough to
> programming that they would consider this exercise as a challenge, I
> guess we need to start with a web-based GUI, yes.

I must be really old fashioned. What every happened to writing
factorial? Or the Abelson/Sussman book?

Does learning programming language X now mean
"Learning how all the elaborate widgets in some web site
conspire to make it possible to type a program in language X into a
window." ?? Or worse,
"Learning how to build a web site in language X"?

>
> A single-page web application with a responsive form in HTML and enough
> metadata that the numeric keyboard is auto-selected on handled devices
> sounds like the minimum viable GUI nowadays, I would venture.

I cannot tell if this is sarcasm or not.

In fact I do have lisp programs that listen and speak and also have
graphical user interfaces for error correction on the speech.

It is quite beside the point that this stuff is written in Lisp.

But I am not :learning lisp: Nor would I expect a student to learn
lisp from these programs. I might expect a student who has learned lisp
to pick up some of these ideas IF he/she were interested in
GUIs, speech, and maybe web stuff. Not otherwise.

Maybe I am unaware of the evidence that
the way to learn language X is to make believe that it is exactly the
same as any other language. (Like picking a brand of gasoline for your
car). And all you have to know about is the operation of your automobile.
>
> In term of Common Lisp I guess it translates to a web-server that would
> contain the application in a specific route, and could contain many such
> small interactive toy (then real) applications.

Really? Instead of exploring a read-eval-print loop you are building
self-contained binaries for the purpose of :learning lisp:?
>
> I have been using hunchentoot and a hacked version of simple-routes to
> do that in the past, with buildapp to produce a self-contained binary
> image, and some more to handle the Unix-like CLI commands one would
> expect (start, stop, restart, pid, reload, etc).
>
> See pgcharts for an example of such a self-contained web application:
>
> https://github.com/dimitr...

Really? In order to :learn lisp: you need to learn about PostgreSQL?
I was kidding.
>
> Maybe â??weâ? could work on a simple kit where it's easy for newcomers

Newcomers? You mean newcomers to Lisp who are already deep into web
site development, know C, Java, Javascript, etc,
to
> add some simple static HTML for the UI and the very simple lisp code for
> the â??backendâ?, and some routing in between those, and all the remaining
> boring details would be provided for already?
>

You can of course invite people to work on pgcharts, writing in Lisp. I
do not expect it to be the right way to :learn lisp:.
RJF

> Regards,
>

Pascal J. Bourguignon

12/27/2015 12:53:00 AM

0

Richard Fateman <fateman@cs.berkeley.edu> writes:

> On 12/26/2015 4:05 PM, Dimitri Fontaine wrote:
>> Richard Fateman <fateman@cs.berkeley.edu> writes:
>>> If you want to learn lisp, do you need to start with a GUI toolkit that
>>> allows the user to click on a button and pop up a numeric keyboard to
>>> enter a top percentage? Sure you can find an interactive programming
>>> environment in Lisps with GUI toolkits, but is that how to begin?
>>
>> Given the current default assumptions of people new enough to
>> programming that they would consider this exercise as a challenge, I
>> guess we need to start with a web-based GUI, yes.
>
> I must be really old fashioned. What every happened to writing
> factorial? Or the Abelson/Sussman book?
>
> Does learning programming language X now mean
> "Learning how all the elaborate widgets in some web site
> conspire to make it possible to type a program in language X into a
> window." ?? Or worse,
> "Learning how to build a web site in language X"?

Yes, unfortunately.

It's even worse: you cann't spend six month teaching programming using
the terminal and files for I/O, you have to teach them how to write 3D
1st person shooter games right from the scratch or they're not
interestedâ?¦

> You can of course invite people to work on pgcharts, writing in
> Lisp. I do not expect it to be the right way to :learn lisp:.

On the other hand, there are all kinds of learner. Recently on #scheme,
people complained that HtDP and SICP were too slow.


--
__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

Barry Margolin

12/27/2015 1:58:00 AM

0

In article <87lh8gg1a8.fsf@kuiper.lan.informatimago.com>,
"Pascal J. Bourguignon" <pjb@informatimago.com> wrote:

> It's even worse: you cann't spend six month teaching programming using
> the terminal and files for I/O, you have to teach them how to write 3D
> 1st person shooter games right from the scratch or they're not
> interestedâ?¦

If the questions I see on StackOverflow are any indication, they usually
start with FizzBuzz, Rock-Paper-Scissor, and Hangman.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

William James

12/27/2015 6:09:00 AM

0

Barry Margolin wrote:

> start with FizzBuzz

Can anyone make a shorter solution in CL?

MatzLisp (Ruby):

def fizzbuzz n
puts (1..n).map{|i|s=[[:fizz][i%3],[:buzz][i%5]].join;s[0]?s:i}
end

fizzbuzz 15
1
2
fizz
4
buzz
fizz
7
8
fizz
buzz
11
fizz
13
14
fizzbuzz

--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunk...
https://www.youtube.com/watch?v=E...

Dimitri Fontaine

12/27/2015 10:58:00 AM

0

Richard Fateman <fateman@cs.berkeley.edu> writes:
> Does learning programming language X now mean
> "Learning how all the elaborate widgets in some web site
> conspire to make it possible to type a program in language X into a window."
> ?? Or worse,
> "Learning how to build a web site in language X"?

You're right that my answer was not about learning lisp, but learning
how to program something useful to its developer and user.

How do you get people interested into learning a programming language
and use tools that are totally disconnected to what they can use and
identify with computing nowadays? (tablets, smart phones, drones, you
name it).

I wish I had an answerâ?¦
--
dim

Tim Hawes

12/28/2015 1:14:00 AM

0

On Saturday, December 26, 2015 at 5:33:18 PM UTC-5, Richard Fateman wrote:
> >
> > But here we use list to provide a user interface for non-lispers.
>
> Well, there are so many things that could go wrong that you are not
> able to check for. Like if the user does not terminate a line, or uses
> a tab. Doesn't a tab go to the next field? Why does it not respond
> to voice input like Siri?
> What if the bill amount was equal to most-positive-double-float,and
> the calculation overflowed?
> What if the user was in certain European countries and insisted on using
> a comma rather than a decimal point.
>
> If you want to learn lisp, do you need to start with a GUI toolkit that
> allows the user to click on a button and pop up a numeric keyboard to
> enter a top percentage? Sure you can find an interactive programming
> environment in Lisps with GUI toolkits, but is that how to begin?
>
> This person was supposedly "learning lisp", not PHP or Ruby or some
> language in which all computations are done with a database system
> in the cloud.
>
>
> Is there really some tutorial lisp book expecting that a beginning lisp
> learner should write a program to read a line of text and parse floating
> point numbers explicitly from it?

Since my call for help seems to be what spurred this topic on, let me give you some background. I am not new to programming. I have been in the IT industry for nearly 20 years, mostly as a UNIX/Linux admin, but always doing automation. My first programming language was Perl, and Korn shell, then C/C++, then PHP, then Python, some Java here and there. I currently work as a Devops engineer. I have been wanting to learn Lisp for some time. I am a late [in my career] adopter of Emacs as a programming editor.

The book I am working through to learn lisp is language agnostic. I'd use the same book to learn any programming language. It is Brian Hogan's Exercises for Programmers https://pragprog.com/book/bhwb/exercises-for-p...

The tip program was the first exercise, but originally is quite simple. Preventing the user from entering negative numbers was an optional challenge. I thought I should learn to do this in lisp, I already know how to solve the same problem in Python, and Java. The book allows me the freedom to skip exercises and come back to them later, so there is not a strong sequential requirement for getting through the book. I could have moved on to the next exercise without calling for help.

I have Peter Seibel's book in a hard-bound form, and am slowly working through it. When I get bored of reading, I pull out Hogan's book and start hammering on some code in Common Lisp.

I am not a fan of gui's, I spend most of may day in front of terminals. I believe learning Common Lisp will launch me into the realm of meta-programming, and make me a better programmer in the languages I have to use in my current multi-[programming]lingual culture I work in, now. Perhaps, some day, I can use Common Lisp to automate writing the code that is needed for automation.

I can quickly pick up just about any C-based programming language that I have never worked with before very quickly. I am finding that Lisp is stretching my understanding, and I have to spend a lot more time with newer concepts. I am not picking it up quickly. But it makes me reminisce 15 years ago, when I first was trying to learn how to program in C.

Paul Rubin

12/28/2015 2:15:00 AM

0

Tim Hawes <trhawes@gmail.com> writes:
> I am finding that Lisp is stretching my understanding, and I have to
> spend a lot more time with newer concepts.

If you're used to Python, except for the metaprogramming aspects, most
of the ideas should carry over to Lisp pretty well. You might like
Conrad Barski's book "Land of Lisp".

If you want to try something really different: http://learnyouah... .