Fork me on GitHub

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.


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


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


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.


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.


I‘ll remember your advice. thanks.


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


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


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


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


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.


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


is that bad practice ?


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


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


There's the project for sandboxing Clojure code, which is used by 4clojure


you shouldn't eval user input


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


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


what do you mean here?


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


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


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.


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


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


is record immutable as well?


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

(defn f [expr] (println expr))
(defmacro m [test arg] `(if ~test ~(f arg)))
(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?


No one? 😞


Use macroexpand


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

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


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


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 but I keep getting Execution error (MalformedURLException) at<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?


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


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


That is why the exception is from the URL constructor


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


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


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


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


okay thanks

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.


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

🎯 1