Fork me on GitHub
#beginners
<
2020-01-26
>
naoki86star09:01:47

Hi, I'm new for clojure and start enjoying it. I've found command history is available in clojure by apt installation(ubuntu16/18). I'd like to know how do I let it enable on 'script installer edition' (from Getting-Started). I wonder what difference from them. thanks.

andy.fingerhut09:01:24

The script installer edition is the one that installs commands named clj and clojure ? If so, clj is a bash script that uses the rlwrap command to enable command history. On Ubuntu Linux, you can install that via sudo apt install rlwrap

naoki86star09:01:16

Thanks to tell me about rlwrap, it is good for my question. Im trying to study rlwrap.

andy.fingerhut09:01:23

Note that quite a few Clojure developers do not care so much about rlwrap support, because they only type Clojure expressions/code into their editor or IDE, and then configure a simple keystroke to send the previous or surrounding Clojure expression to a REPL session.

andy.fingerhut09:01:31

Since you then have the full power of your editor/IDE to manipulate code, and can store it in a file, etc., it can do more things than rlwrap can.

naoki86star09:01:06

I‘ll remember your advice. thanks.

porkostomus09:01:16

Ah, I believe you may be referring to the clojure command provided by the Leiningen package on Debian which starts a lein repl.

andy.fingerhut09:01:20

rlwrap is useful for wrapping almost any command and providing command history and line-editing functionality, so useful to know for other reasons.

naoki86star09:01:07

Leinin package is first for me also. Id like to check it.

porkostomus09:01:14

If you installed clojure via apt, that's indeed what it was.

naoki86star10:01:08

Thank you for all advices, hints, knowleges. I get to know that knowing leiningen let me be able to read more repositories from small example to large project. I'll learn leiningen I guess actually rlwrap is useful not just clojure but others seen. I'm lucky to got it. good-night.

abdullahibra13:01:27

is it safe to save clojure text code into db and fetch and invoke on demand ?

abdullahibra13:01:47

is that bad practice ?

abdullahibra13:01:14

my goal is: i want to make each user has extendible set of functions to apply on thein input data

abdullahibra13:01:05

so i will save the code into the db per user, and insert as many methods to the user and fetch once i want to invoke them

porkostomus12:01:13

There's the https://github.com/Raynes/clojail project for sandboxing Clojure code, which is used by 4clojure

michael.e.loughlin13:01:04

you shouldn't eval user input

michael.e.loughlin14:01:19

It's very difficult, if not impossible, to stop attackers exploiting vulnerabilities this way. You're opening your server up for remote code execution.

michael.e.loughlin14:01:24

You could save a list of representative command names against each user, then in your code match the command names against your own functions

abdullahibra14:01:53

what do you mean here?

abdullahibra14:01:57

i'm trying to make it very extendable per user, ...

abdullahibra14:01:36

so each time i wanna support new method for specific user, i just ingest the code for it and use the name, but it will be dangerous as you said

abdullahibra14:01:50

what alternatives can you think of?

eamonn.sullivan15:01:23

hi, this is (hopefully) a simple question. I have bit of code, in a separate namespace, that wraps a REST API. It has functions for the various endpoints and methods. However, how do I let the callers of these functions supply some configuration information (host, port, etc.) that each of the endpoints need? What's the Clojure-idiomatic equivalent of a constructor, I guess is what I'm trying to figure out.

eamonn.sullivan15:01:06

In other words, I want the code requiring my set of functions to provide the configuration just once and then go on and use the endpoint/method functions without further ado.

eamonn.sullivan15:01:06

In other words, I want the code requiring my set of functions to provide the configuration just once and then go on and use the endpoint/method functions without further ado.

matti.uusitalo15:01:09

Usually these kind of functions take the configuration as their first argument.

eamonn.sullivan15:01:03

I see, ok. So I'd create the config map in my calling application and pass it in as the first argument for every method. Seems a little awkward, but if that's idiomatic way...

eamonn.sullivan15:01:47

Or maybe I can provide an init or config function and have the module squirrel that away somewhere.

eamonn.sullivan15:01:31

But then I'd have to check whether the config/init was called in every method, which brings us back to awkward...

edenferreira17:01:48

You/the client of your code can partial apply the configurations if they are static (def new-endpoint-fn (partial endpoint-fn config-map))

feikas16:01:06

Why records are better than maps? are they more performant or something else? or maybe convenience?...

vachichng16:01:53

for performance, but you better start with maps and then refactor or no to records

feikas16:01:27

is record immutable as well?

yokoyama.km16:01:33

Hello, I'm still struggling to understand some subtleties of macros. As an example, consider the following definitions:

(defn f [expr] (println expr))
and
(defmacro m [test arg] `(if ~test ~(f arg)))
Calling
(m false (2 2))
causes the REPL to print (2 2) and nil , leading me to conclude that arg is not evaluated (since it is an invalid expression and it should blow up). However, if I slightly change the definition of m to m1 as follows
(defmacro m1 [test arg] `(if ~test ~(f (1 1))))
and call
(m1 false (2 2))
it does fail: Unexpected error (ClassCastException) macroexpanding m1 at (REPL:1:1) [...] . Why is it that?

hiredman16:01:30

Use macroexpand

yokoyama.km16:01:33

I did. It does not help that much. m expands to

user=> (macroexpand '(m false (2 2)))
(2 2)
(if false nil)

noisesmith18:01:45

what that reveals is that the macro prints as a side effect while expanding, then emits (if false nil) as the code that will get run when the macro is used

jdwoodsy117:01:30

okay I have a question about parsing xml. I'm making a http request and getting an xml response in the body. I'm trying to parse that xml data to get out a list of <DATA> items. Trying to follow http://clojure-doc.org/articles/tutorials/parsing_xml_with_zippers.html but I keep getting Execution error (MalformedURLException) at http://java.net.URL/<init> no protocol: <RETS ReplyCode="0" ReplyText="Operation Successful"> <COUNT Records="3330" /> <DELIMITER value="09" /> <COLUMNS> LA1_AgentID LA1_AgentLicenseID LA1_HiddenUsCID LA1_PhoneNumber1 LA1_PhoneNumber1CountryCodeId LA1_PhoneNumber1Desc LA1_PhoneNumber1Ext LA1_PhoneNumber2 LA1_PhoneNumber2CountryCodeId LA1_PhoneNumber2Desc LA1_PhoneNumber2Ext LA1_Status LA1_UserFirstName LA1_UserLastName LA1_UserMI LA1_WebPage LA2_AgentID LA2_HiddenUsCID LA2_PhoneNumber1 LA2_PhoneNumber1CountryCodeId LA2_PhoneNumber1Desc LA2_PhoneNumber1Ext LA2_PhoneNumber2 LA2_PhoneNumber2CountryCodeId LA2_PhoneNumber2Desc LA2_PhoneNumber2Ext LA2_Status LA2_UserFirstName LA2_UserLastName LA2_UserMI LA2_WebPage LFD_CONSTRUCTION_2 LFD_COOLING_1 LFD_DOCSONFILE_19 LFD_FIREPLACE_3 LFD_GARAGETYPE_4 LFD_GREENBUILDINGCERT_226 LFD_HANDICAPACCESSIBLE_111 LFD_HEATING_5 LFD_INCLUDEDKITCHENFEATURES_6 LFD_LANDUSE_7 LFD_LOTFEATURES_11 LFD_POOLSPA_12 LFD_ROOF_13 LFD_SEWER_14 LFD_SPRINKLERSYSTEM_8 LFD_STRUCTUREFEATURES_15LFD_TERMS_16 LFD_WATERHEATER_227 LFD_WATER_17 LMD_MP_AddressLine LMD_MP_Latitude LMD_MP_Longitude LMD_MP_MatchCode LMD_MP_MatchedMethod LMD_MP_PostalCode LMD_MP_PrimaryCity LMD_MP_Quality LMD_MP_SecondaryCity LMD_MP_Subdivision LMD_MP_UpdateDate LMD_MP_ZoomLevel LM_Char10_1 LM_Char10_11 LM_Char10_12 LM_Char10_17 LM_Char10_18 LM_Char10_19 LM_Char10_2 LM_Char10_20 LM_Char10_21 LM_Char10_22 LM_Char10_23 LM_Char10_24 LM_Char10_25 LM_Char10_26 LM_Char10_27 LM_Char10_28 LM_Char10_29 LM_Char10_3 LM_Char10_30 LM_Char10_4 LM_Char10_5 LM_Char1_1 LM_Char1_19 LM_Char1_2 LM_Char1_5 LM_Char1_8 LM_Char25_12 LM_Char25_14 LM_Char25_15 LM_Char25_16 LM_Char25_17 LM_Char25_6 LM_Char50_1 LM_DateTime_1 LM_Dec_12 LM_Dec_14 LM_Dec_15 LM_Dec_16 LM_Dec_3 LM_Dec_4 LM_Dec_5 LM_Dec_6 LM_Dec_8 LM_Dec_9 LM_Int1_20 LM_Int2_1 LM_Int2_10 LM_Int2_11 LM_Int2_12 LM_Int2_13 LM_Int2_2 LM_Int2_3 LM_Int2_4 LM_Int2_5 LM_Int2_6 LM_Int2_8 LM_Int4_1 LM_Int4_4 LM_char100_1 LM_char10_31 LM_char10_32 LM_char10_33 LM_char10_34 LM_char10_35 LM_char10_39 LM_char10_40 LM_char10_41 LM_char10_42 LM_char10_43 LM_char10_44 LM_char10_45 LM_char10_48 LM_char10_69 LM_char10_70 LM_char1_39 LM_char1_40 LM_char255_1 LM_char5_1 LM_char5_10 LM_char5_11 LM_char5_12 LM_char5_13 LM_char5_14 LM_char5_15 LM_char5_16 LM_char5_17 LM_char5_18 LM_char5_2 LM_char5_21 LM_char5_3 LM_char5_4 LM_char5_5 LM_char5_6 LM_char5_7 LM_char5_8 LM_char5_9 LM_int4_27 LO1_BranchOfOrgID LO1_HiddenOrgID LO1_HiddenOtyIDLO1_OrgAddress2 LO1_OrgAddressStreet LO1_OrgCity LO1_OrgState LO1_OrgZip LO1_OrganizationName LO1_PhoneNumber1 LO1_PhoneNumber1CountryCodeId LO1_PhoneNumber1Desc LO1_PhoneNumber1Ext LO1_ShortName LO1_WebPage LO1_board_id LO2_BranchOfOrgID LO2_HiddenOrgID LO2_HiddenOtyID LO2_OrgAddress2 LO2_OrgAddressStreet LO2_OrgCity LO2_OrgState LO2_OrgZip LO2_OrganizationName LO2_PhoneNumber1 LO2_PhoneNumber1CountryCodeId LO2_PhoneNumber1Desc LO2_PhoneNumber1Ext LO2_ShortName LO2_WebPage LO2_board_id LR_remarks22 LV_vow_address LV_vow_avm LV_vow_comment LV_vow_include L_Address L_Address2 L_AddressDirection L_AddressNumber L_AddressSearchNumber L_AddressStreet L_Area L_AskingPrice L_City L_Class L_DOM L_DisplayId L_FirstPhotoAddDt L_IdxInclude L_Keyword1 L_Keyword2 L_Keyword5 L_Keyword6 L_Keyword7 L_LastDocUpdate L_Last_Photo_updt L_ListAgent1 L_ListAgent2 L_ListOffice1 L_ListOffice2 L_ListingDate L_ListingID L_PictureCount L_PriceDate L_PricePerSQFT L_Remarks L_SaleRent L_State L_Status L_StatusCatID L_StatusDate L_StatusID L_SystemPrice L_Type_ L_UpdateDate L_Zip VT_ExtVTourURL1 VT_ExtVTourURL2 VT_ExtVTourURL3 VT_ExtVTourURL4 VT_ExtVTourURL5 VT_VTourURL </COLUMNS> <DATA> 553819 AB8067 Realtor United States (+1) Cell Home MLS and BOARD Gary Tribble Hardi Type Siding Central Air One,Gas Detached Forced Air,Heat Pump,Propane Oven/Range Freestanding,Refrigerator,Washer,Dryer Barn,Horses,Private Road,Rolling Topography TARGET:117 Septic Covered Patio/Deck,Hardwood,Den/Office,Family Room,Carpet Electric Individual Well 46.7712615011932 -116.695961845012 0 1 1 2016-06-08T19:05:30.3 17 Latah Upper Main Main 0 Down Main 0 Main No No No No No AF Agriculture/Forestry No No 40N03W340035 519.36 108.67 10750.16 20244.78 3 1 1 1 02580 2016 2 1 0 1200 3780 0 456 456 0 2009 Past Troy towards Deary, left onto White Pine Flats, Home on Left. Call Office for more details. Main Yes Not Applicable Troy School District #54 Troy Troy Troy No 16057 0 Not Applicable $ In associated documents Tax Parcel No. 40N03W340035 4236 3003 3003 Real Estate Office 128 E 3rd Moscow ID 83843 Latah Realty, LLC United States (+1) Off 12174 Latah County Board of Realtors HORSE HAVEN- Gorgeous 4,200 sq ft custom built home w/ extensive covered porches that overlook 108 AC horse farm. Wood floors, tons of custom oak cabinets and book shelves, large windows w/ views in all directions, 924 sq ft 2nd floor master suite. For your horses: 25,500 sq ft super high quality horse building. Within is a 73&apos; x 197&apos; full size dressage arena, 1,900 sq ft tack room/guest quarters, hay and equipment storage, stalls etc. Plus extra 48 x 66 barn and deep water pond. NEW IN 2009 AND PRIVATE - Gary Tribble, Cell: , Latah Realty, LLC, Off: , Yes Yes No Yes 0000 White Pine Flats 0000 0 White Pine Flats Latah County - 2075 2200000 Troy Residential 3609 116864 2017-06-06T22:05:27 Yes Over 40 Acres 3 4 6 - 10 Years Two Story 2012-05-25T15:41:00 2017-06-06T22:06:00 19517 3003 2010-03-10 116864 18 2016-07-07 519.36 HORSE HAVEN- Gorgeous 4,200 sq ft custom built home w/ extensive covered porches that overlook 108 AC horse farm. Wood floors, tons of custom oak cabinets and book shelves, large windows w/ views in all directions, 924 sq ft 2nd floor master suite. For your horses: 25,500 sq ft super high quality horse building. Within is a 73&apos; x 197&apos; full size dressage arena, 1,900 sq ft tack room/guest quarters, hay and equipment storage, stalls etc. Plus extra 48 x 66 barn and deep water pond. NEW IN 2009 AND PRIVATE For Sale ID Active Active 0 2200000 Single Family w/ Acreage 2019-11-20T15:57:27.7 83871 </DATA> <MAXROWS /> <RETS-STATUS ReplyCode="0" ReplyText="Operation Successful" /> </RETS> what am I doing wrong?

jdwoodsy117:01:16

I'm passing the xml to this function (defn formData [x] ((xml/parse x )) )

hiredman17:01:00

Xml/parse assumes if you pass it a string that string is a url pointing to the xml you want parsed

hiredman17:01:19

That is why the exception is from the URL constructor

jdwoodsy117:01:01

So I need to save the xml to disk to make it work?

hiredman17:01:30

I would take a closer look at that tutorial, I can't point to any specific part the code examples in it don't load for me, but I assume they do for you

jdwoodsy117:01:43

they do, the tutorial is using the file system so I'm doing it a little different

hiredman17:01:59

Ah, they load of I request the desktop site, checkout the putting it altogether section

eamonn.sullivan18:01:31

OK I have been staring at and fiddling with this code for a couple of hours now and can't figure out the problem: (defn configure "Configure request options and url" [{:keys [url keystore keystore-pass] :or {:url "" :keystore "/some/path/file.p12" :keystore-pass "super-secret-password"} :as opts}] opts) The error is: Syntax error macroexpanding clojure.core/defn at (*cider-repl git/cosmos-login:localhost:41267(clj)*:70:7). {:keys [url keystore keystore-pass], :or {:url "", :keystore "/some/path/file.p12", :keystore-pass "super-secret-password"}, :as opts} - failed: vector? at: [:fn-tail :arity-n :bodies :params] spec: :clojure.core.specs.alpha/param-list ({:keys [url keystore keystore-pass], :or {:url "", :keystore "/some/path/file.p12", :keystore-pass "super-secret-password"}, :as opts}) - failed: Extra input at: [:fn-tail :arity-1 :params] spec: :clojure.core.specs.alpha/param-list I understand that the underlying error is "Extra input", but I don't understand where it is telling me.

hiredman18:01:23

Double check the syntax of :or

lennart.buit18:01:44

yeah, pretty sure that should be symbols instead of keywords

eamonn.sullivan18:01:24

Ah! Thank you. Should have asked this a couple of hours ago.

lennart.buit18:01:38

that said; the spec error is not great at pointing out the problem in your :or