You can structure it any way you like


GetPrices1=: 4 : 0
sel =. ' cl_lname, cl_title, '
sel =. sel,'pp_year, pp_id, pr_mfd, pr_price'
from =. ' (price_profiles INNER JOIN'
from =. from,' prices ON pp_id = pr_pp) INNER JOIN'
from =. from,'(clients INNER JOIN revs ON cl_id = '
from =. from,'rv_client) ON pp_id = rv_pp'
where =.' cl_id=? AND rv_validuntil Is Null'
orderby =. ' cl_lname, pr_mfd;'
sqlcmd =. ' SELECT ',sel
sqlcmd =. sqlcmd,' FROM ',from
sqlcmd =. sqlcmd,' WHERE ',where
sqlcmd =. sqlcmd,' ORDER BY ',orderby
NB. profiles=. > _3 {."1 }. y query__db sqlcmd
NB. 'pp mfd prc'=: |: data
NB. profiles=. ((_1}.pp~:1|.pp),1) <;.2 profiles
)


SEL =: ' cl_lname, cl_title, '
SEL =: SEL,'pp_year, pp_id, pr_mfd, pr_price'
FROM =: ' (price_profiles INNER JOIN'
FROM =: FROM,' prices ON pp_id = pr_pp) INNER JOIN'
FROM =: FROM,'(clients INNER JOIN revs ON cl_id = '
FROM =: FROM,'rv_client) ON pp_id = rv_pp'
WHERE =: ' cl_id=? AND rv_validuntil Is Null'
ORDERBY =: ' cl_lname, pr_mfd;'

GetPrices2=: 4 : 0
('sel';'from';'where';'orderby') =.x
sqlcmd =. ' SELECT ',sel
sqlcmd =. sqlcmd,' FROM ',from
sqlcmd =. sqlcmd,' WHERE ',where
sqlcmd =. sqlcmd,' ORDER BY ',orderby
NB. profiles=. > _3 {."1 }. y query__db sqlcmd
NB. 'pp mfd prc'=: |: data
NB. profiles=. ((_1}.pp~:1|.pp),1) <;.2 profiles
)

  1 GetPrices1 3
SELECT  cl_lname, cl_title, pp_year, pp_id, pr_mfd, pr_price FROM
(price...

  (SEL;FROM;WHERE;ORDERBY) GetPrices2 3
SELECT  cl_lname, cl_title, pp_year, pp_id, pr_mfd, pr_price FROM
(price...



2007/2/14, Sherlock, Ric <[EMAIL PROTECTED]>:

Thanks for the dyad example and yes stored procedures might be a good
idea but I'm using SQLite via Oleg's package and that doesn't support
stored procedures. Bjorn, in my second (fuller) post on the subject I
discounted appending to the line over multiple lines. I don't know about
you but I find it tedious & messy (and much harder to copy/paste ;-) )

I think the "keep it simple" advice I've had from a number of people is
probably pretty sound, so will probably go that way for now.

Being quite new to J I'm not really sure how important it is for the
debugger to handle this sort of case (especially the anonymous), vs
coming up with a way of allowing nesting. Would this be useful in more
general cases, or would finding some way to allow nesting, render it a
non-issue?
To me, allowing nesting seems simpler and would result in more readable
code, but I'm sure I'm not aware of all the issues.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Miller, Raul D
Sent: Thursday, 15 February 2007 01:39
To: Programming forum
Subject: RE: [Jprogramming] Possible to nest
multilinenoundefinitionwithinverb definition?

Dan Bron wrote:
> I would warn you away from this pattern if you use or intend to use
> the J debugging facilities.  The dyad within the monad GetPrice is
> anonymous, and consequently atomic from the J debugger's POV; hence
> undebuggable.

I consider this a defect in the debugger, and refuse to let it impact my
code.

Note that this defect also matters for code like:

verba=:3 :0"1

or

verbb=:3 :0&.>

etc.

When I need to use that aspect of the debugger to isolate a problem with
my code, I'm already in a position where I need to be re-writing my
code.  And the debugger will tell me which specific function is having
the problem.  So, in that case, I first rewrite the function to make the
debugger happy with it, and then use the debugger to find the flaw, and
then I fix the problem, test some more, and quite probably rewrite some
more based on the outcome of my testing.

But you're right that this issue does warrant an occasional warning.

Finally note that for SQL, I prefer using stored procedures over inline
code.  There are times when I can't (mysql doesn't support stored
procedures), so sometimes I have to make allowences there, too.

--
Raul


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm




--
Björn Helgason, Verkfræðingur
Fugl&Fiskur ehf, Þerneyjarsund 23, Box 127
801 Grímsnes ,t-póst: [EMAIL PROTECTED]
Skype: gosiminn, gsm: +3546985532
Landslags og skrúðgarðagerð, gröfuþjónusta
http://groups.google.com/group/J-Programming


Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans

góður kennari getur stigið á tær án þess að glansinn fari af skónum
         /|_      .-----------------------------------.
        ,'  .\  /  | Með léttri lund verður        |
    ,--'    _,'   | Dagurinn í dag                     |
   /       /       | Enn betri en gærdagurinn  |
  (   -.  |        `-----------------------------------'
  |     ) |        (\_ _/)
 (`-.  '--.)       (='.'=)
  `. )----'        (")_(")
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to