Fork me on GitHub
#beginners
<
2024-04-25
>
Jim Newton07:04:59

I'm trying to summarize the various printing functions in clojure. Many functions reference a variable named *flush-on-newline* but I don't find explicit documentation for this variable. Are variables documented in https://clojuredocs.org

tomd07:04:09

> When set to true, output will be flushed whenever a newline is printed. > Defaults to true.

tomd07:04:05

It's in its docstring. Clojuredocs is unofficial - community driven. Some things are missing I guess.

Jim Newton07:04:20

I found the following in core.clj

(add-doc-and-meta *flush-on-newline*
  "When set to true, output will be flushed whenever a newline is printed.

  Defaults to true."
  {:added "1.0"}) 

Jim Newton07:04:45

I guess that means the variable is defined in the underlying java code, and its docstring and meta data are added at the clojure level?

👍 1
Jason Bullers19:04:44

Is there a function in Clojure to get progressively larger "windows" of some data? Say I have ["a" "b" "c" "d"], I'd want to get something like (["a"] ["a" "b"] ["a" "b" "c"] ["a" "b" "c" "d"]) I've done sliding windows before with partition, but this is more expanding than sliding...

Jason Bullers20:04:53

Ah interesting. conj as the reducing function?

hiredman20:04:01

sure, or just use whatever you were planning to do with the windows as the reducing function

👍 1
Guild Navigator20:04:49

Why does lein take so long to run?

time lein
Leiningen is a tool for working with Clojure projects.

Several tasks are available:
change              Rewrite project.clj with f applied to the value at key-or-path.
check               Check syntax and warn on reflection.
classpath           Write the classpath of the current project to output-file.
clean               Removes all files from paths in clean-targets for a project
compile             Compile Clojure source into .class files.
deploy              Deploy jar and pom to remote repository.
deps                Download and examine dependencies.
do                  Higher-order task to perform other tasks in succession.
help                Display a list of tasks or help for a given task or subtask.
install             Install jar and pom to the local repository; typically ~/.m2.
jar                 Package up all the project's files into a jar file.
javac               Compile Java source files.
new                 Generate scaffolding for a new project based on a template.
plugin              DEPRECATED. Please use the :user profile instead.
pom                 Write a pom.xml file to disk for Maven interoperability.
release             Perform release tasks.
repl                Start a repl session either with the current project or standalone.
retest              Run only the test namespaces which failed last time around.
run                 Run the project's -main function.
search              Search Central and Clojars for published artifacts.
show-profiles       List all available profiles or display one if given an argument.
test                Run the project's tests.
trampoline          Run a task without nesting the project's JVM inside Leiningen's.
uberjar             Package up the project files and all dependencies into a jar file.
update-in           Perform arbitrary transformations on your project map.
upgrade             Upgrade Leiningen to specified version or latest stable.
vcs                 Interact with the version control system.
version             Print version for Leiningen and the current JVM.
with-profile        Apply the given task with the profile(s) specified.

Run `lein help $TASK` for details.

Global Options:
  -o             Run a task offline.
  -U             Run a task after forcing update of snapshots.
  -h, --help     Print this help or help for a specific task.
  -v, --version  Print Leiningen's version.

These aliases are available:
downgrade, expands to upgrade

See also: readme, faq, tutorial, news, sample, profiles, deploying, gpg,
mixed-source, templates, and copying.

________________________________________________________
Executed in    3.24 secs    fish           external
   usr time    3.54 secs    0.22 millis    3.54 secs
   sys time    0.50 secs    1.89 millis    0.50 secs
If this is indicative of Clojure's performance, I'm shopping elsewhere.

respatialized20:04:59

For compiled projects, it isn’t. The breakdown of the flamegraph here gives some insights into what lein is doing under the hood. http://clojure-goes-fast.com/blog/clojures-slow-start/

Alex Miller (Clojure team)20:04:11

those are distractions really. shopping for trying to do what? Clojure's primary use case is either running a long-running REPL for interactive development, or long-running situated server programs. In both cases, these often run for hours, days, weeks. If your goal is short command line programs, there are faster paths using babashka for scripting uses, or Graal for fast starting server programs

3
Alex Miller (Clojure team)20:04:41

that timing for lein looks slow to me, but you are generally running a JVM to do anything with Clojure. there are other tools like the official Clojure CLI, and faster versions of that using babashka or native if you need it

Guild Navigator20:04:38

This is using Graal, for context.

Alex Miller (Clojure team)20:04:28

not sure what that means, is "this" what you want to do or referring to lein (which does not use Graal afaik)?

Guild Navigator20:04:12

So my ultimate goal here is to figure out how to get an AWS Lambda function running using Clojure. I'm very new to Clojure, and I'm starting with Leiningen. Cold start times are a huge problem with Lambda and Java.

Alex Miller (Clojure team)20:04:59

there is a lot of prior art specifically about this, maybe check out #C1AL322AJ here, should find some good links

Jason Bullers20:04:49

What's the reason for it being called max-key instead of, say, max-by? It seems that the "key" can be any function that returns an integer, so really it's about finding the max by some computation, not exclusively by some key/property. Any historical insights?

ghadi21:04:38

the computation returns a key for each given element

Jason Bullers21:04:03

Hmm... I see. The docs show it as (max-key k x) which I thought implies that the first argument is meant to be a literal key. I expected something more like (max-by f x) Would you say it's common to name function parameters around what they're logically for (in this case, generating a key for comparison) rather than what they literally are (a function of x->int)?

phill21:04:39

The first arg may be a real key, if the map's keys are keywords, since keywords are usable in function position to fetch from a map.

Bob B22:04:33

I'd speculate that 'by' is aimed at collections and more arbitrary return types, whereas 'key' might be more just an extension on min and max, which are variadic and aimed at comparing numbers