Open Side Menu Go to the Top

09-19-2012 , 11:46 PM
Quote:
Originally Posted by Ankimo
Is it possible the field that's going into that int column is null? Sometimes when you translate fields on a web form into Java, you need to take care of blank fields.
This is where my thought process started and the answer is slightly more complex than this. Basically, I had to create local bindings, but the trick is *where* to put the local bindings. I have some notion of how Clojure deals with let bindings (search "Clojure destructuring" for more information), but sometimes its confusing for me since it's at odds with how Scheme deals with let bindings. The differences aren't huge exactly, but just enough to make you stop and reconsider. FWIW, destructuring is friggin cool once you get a few snippets working.

I'm not sure how used to looking at Lisp syntax you are, but here's a part of the code I have right now, which takes grabs the username session variable and assigns it a local binding, and displays the user's name like so on the form. This actually forces me to drop my entire database because I figure it's easier to go ahead and upload a new database with all the char(x) fields defaulting to empty string instead of updating each table, otherwise, everything displays as Null if there is no information:



If you look at the let binding next to the -- [:i -- tag, you can see destructuring in action:

Code:
(defpage "/name-and-contact" []
   (common/res-heads
   (let [suser (sesh/get :uname)] 
	(def suser-first-name
		(select db/jhfirstnames
			(fields :firstname)
			(where {:username suser})))
	[:div#formFields
		(form-to [:post "/name-and-contact"]
			[:p "First Name: " 
				[:i (let [[{fname :firstname}] suser-first-name]
					(format "%s" fname))]
			[:br](text-field "firstName")] 
	(submit-button "Update"))])))
The above code does what it is supposed to do. The next piece looks like it works exactly as the above code, but displays this:



Code:
(defpage "/name-and-contact" []
   (common/res-heads
   (let [suser (sesh/get :uname)] 
	[:div#formFields
		(form-to [:post "/name-and-contact"]
			[:p "First Name: " 
			[:i (def suser-first-name
					(select db/jhfirstnames
						(fields :firstname)
						(where {:username suser})))
				(let [[{fname :firstname}] suser-first-name]
					(format "%s" fname))]
			[:br](text-field "firstName")] 
		(submit-button "Update"))])))
The only difference is that I defined the variable in a different place. It makes no real sense to me. The moral of the story is that many odd things happen depending on the location of the definitions and local bindings.

Moving onto the database entries, you can see that there has to be a local binding in in the if-statement that first parses out the numbers in the strings and converts them to integers (same with dates, etc):

Code:
(if (not (= myNumber "-"))
   (let [myInt (Integer/parseInt myNumber)]
	(update db/myTable 
	       (set-fields {:myCol myInt})
		(where {:username suser}))))
There doesn't seem to be any good reason that this next piece of code wouldn't work because lisp generally reads "in to out", but there is some mis-ordering here, so the nested function calls do... what exactly?:

Code:
(defpage [:post "/other-page"] {:keys [myNumber]} 
   (let [suser (sesh/get :uname)]
	(if (not (= myNumber "-"))
		(update db/myTable 
			(set-fields {:myCol (Integer/parseInt myInt})
			(where {:username suser}))))))
So, with code 1 working as planned, wouldn't it make sense to have local bindings all in one let? Nope.

Code:
(defpage [:post "/other-page"] {:keys [myNumber]} 
   (let [suser (sesh/get :uname)
	 myInt (Integer/parseInt myNumber)]
	(if (not (= myNumber "-"))
		(update db/myTable 
			(set-fields {:myCol myInt})
			(where {:username suser})))))
If you're really interested in seeing what exactly is happening and how everything is nested and interacting, you would want to copy-paste the above into your favorite text-editor and pay close attention to where the parentheses land.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
09-19-2012 , 11:47 PM
Quote:
Originally Posted by clowntable
I used foreach in Prolog today...feels kind of odd but also made the code more clear imo so it stays.
foreach is awesome! Every language should have it, dammit.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:50 AM
Yes but it kind of breaks the paradigm since it smells pretty imperative which is why it felt a little odd. I mean it's even called:

(foreach() ... do)

I'll post the exact code snipped later
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 11:25 AM
A friend of mine is working on a project and he wants a site where 'customers' can login and then have the option to purchase a small (5-10) set of products. This is basically a very small, private, ecommerce site and I am sure there is a service out there which provides this sort of functionality, but google hasn't thrown anything up yet. Any ideas?

Thanks
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 11:29 AM
I keep reading good things about Shopify, might want to take a look at that.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 11:40 AM
Ha, was literally just looking at the Shopify wiki. It looks like you can create a private (password protected) store. The only potential issue I can see with Shopify is if you want to offer different prices to certain customers, but I dont think that would be a show stopper.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 01:09 PM
What flavour of linux are you using? You will probably find that installing it via a package manager is much simpler, unless you need the absolute latest version.

For ubuntu sudo apt-get install python-numpy python-scipy

Source: http://www.scipy.org/Installing_SciPy/Linux
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 01:34 PM
I only just now realized a) who that is in MrWooster's avatar and b) what the username is referencing.

Haven't seen the show itself yet though.

</dumb>
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:00 PM
I don't know who that is or what the name is referencing or what show you're talking about. Enlighten me please
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:07 PM
Quote:
Originally Posted by clowntable
I don't know who that is or what the name is referencing or what show you're talking about. Enlighten me please
Hugh Laurie in Jeeves and Wooster. Laurie plays Wooster so... MrWooster.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:11 PM
Yeah never heard of that one, thx
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:12 PM
Fry and Laurie are apparently very good together. I *should* see it sometime.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:37 PM
It is a little dated but the Jeeves books were very funny at the time, not a lot of gentleman of leisure around anymore though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:47 PM
Said foreach...

Code:
playerList_globalWorld_localWorlds(PlayerList,World,LocalWorlds) :-
  (foreach(Player,PlayerList), foreach(PlayerWorld,LocalWorlds), param(World) do
    huHoldemPlayer_globalWorld_playersWorld(Player,World,PlayerWorld)
  ).
And a variable naming question...would you pick "playersWorld" or "playerWorld" as a variable name for the world of a player? I'm also not a fan of the "global" so I'll just drop it and rename every global world to just world.
Alternative B would be renaming the predicate something like world_localWorld_of(World,LocalWorld,Player) or something

Last edited by clowntable; 09-20-2012 at 02:56 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 02:54 PM
Neil S is correct, my account is named after Bertie Wooster. Dated, but brilliant show. At the time Hugh Laurie and Stven Fry were not really that famous... look at them now.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 04:09 PM
Quote:
Originally Posted by clowntable
Said foreach...

Code:
playerList_globalWorld_localWorlds(PlayerList,World,LocalWorlds) :-
  (foreach(Player,PlayerList), foreach(PlayerWorld,LocalWorlds), param(World) do
    huHoldemPlayer_globalWorld_playersWorld(Player,World,PlayerWorld)
  ).
It took a little bit of staring, but I see what its doing now. I thought that foreach executed a function on each element of a data collection and treated elements as individuals. It looks like your implementation creates a multi-dimensional collection and dumps it all into the hu...World function. Is that right?

When I said every language should have a foreach, I was thinking of something closer to:

foreach([1, 2, 3, 4], +1)
>> [2, 3, 4, 5]
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 04:11 PM
In my world, MrWooster is someone that posts on 2+2. Never saw the show + I'm American.

I do imagine that it is better than AbFab.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 04:39 PM
Since some of you might be interested in this...pretty sick deal here right now:

https://www.getbuckyballs.com/order/buckyballs/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 04:47 PM
Quote:
Originally Posted by jalexand42
Since some of you might be interested in this...pretty sick deal here right now:

https://www.getbuckyballs.com/order/buckyballs/
nice, thanks
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 04:50 PM
jalex,

how many do you think you need to make good stuff? 500? 1k?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 05:57 PM
Quote:
Originally Posted by gaming_mouse
jalex,

how many do you think you need to make good stuff? 500? 1k?
I have 2 sets on my desk, I just ordered 2 for each of my kids.

I'd say 4 sets gives you a tonnnn. 2 works well for me if i'm keeping my hands busy during a meeting or thinking through something.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 05:59 PM
Quote:
Originally Posted by daveT
In my world, MrWooster is someone that posts on 2+2. Never saw the show + I'm American.

I do imagine that it is better than AbFab.
Slow down a second.... you saying that AbFab is not a great show?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 06:24 PM
AbFab grew on me, but it took a few years. I was only 15 or 16 when I first saw it. After I was in my 20s, I started to see the brilliance of the show.

Don't ask me for details. I haven't seen the show for a long time.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 06:27 PM
Aren't buckyballs banned because stupid people eat them and the magnets **** up their insides?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
09-20-2012 , 06:35 PM
Quote:
Originally Posted by daveT
AbFab grew on me, but it took a few years. I was only 15 or 16 when I first saw it. After I was in my 20s, I started to see the brilliance of the show.

Don't ask me for details. I haven't seen the show for a long time.
Not watched it for a while either, but it sounds like we had very similar experiences with the show.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m