sorting a list based on the order of its items in another list

2017-12-12 Thread Deyan Yotsov

Hello,

I have one list of potentially up to 2 million strings: big-list.

Then I have another list, small-list, the elements of which are a subset 
of the elements of big-list.


I want to sort the elements in small-list so that they become sorted in 
the same way in which they are sorted in big-list.


The most obvious way to do this, for me, is:

(filter #(some #{%} small-list) big-list)

(one by one we take the elements from big-list, we check if they are in 
small-list, and if they are, we add them (in big-list order) to the result)


But of course this performs extremely poorly, especially if small-list 
is say 1M elements, and big-list is 2M elements.


Suggestions?

Thank you,

Deyan

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups "Clojure" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sorting a list based on the order of its items in another list

2017-12-12 Thread Deyan Yotsov
PS: I just realized that the code, as I wrote it, will not work, as 
nesting of # is forbidden.


My actual code is:

(defn is-element-in-list [e l]
  (some #{e} l))

(filter #(is-element-in-list % small-list) big-list)

Sorry about that.

Deyan


On 12/12/2017 02:24 PM, Deyan Yotsov wrote:

Hello,

I have one list of potentially up to 2 million strings: big-list.

Then I have another list, small-list, the elements of which are a 
subset of the elements of big-list.


I want to sort the elements in small-list so that they become sorted 
in the same way in which they are sorted in big-list.


The most obvious way to do this, for me, is:

(filter #(some #{%} small-list) big-list)

(one by one we take the elements from big-list, we check if they are 
in small-list, and if they are, we add them (in big-list order) to the 
result)


But of course this performs extremely poorly, especially if small-list 
is say 1M elements, and big-list is 2M elements.


Suggestions?

Thank you,

Deyan



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups "Clojure" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sorting a list based on the order of its items in another list

2017-12-12 Thread Gary Trakhman
How about (filter (set small-list) big-list) ?

On Dec 12, 2017 8:25 AM, "Deyan Yotsov"  wrote:

> Hello,
>
> I have one list of potentially up to 2 million strings: big-list.
>
> Then I have another list, small-list, the elements of which are a subset
> of the elements of big-list.
>
> I want to sort the elements in small-list so that they become sorted in
> the same way in which they are sorted in big-list.
>
> The most obvious way to do this, for me, is:
>
> (filter #(some #{%} small-list) big-list)
>
> (one by one we take the elements from big-list, we check if they are in
> small-list, and if they are, we add them (in big-list order) to the result)
>
> But of course this performs extremely poorly, especially if small-list is
> say 1M elements, and big-list is 2M elements.
>
> Suggestions?
>
> Thank you,
>
> Deyan
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sorting a list based on the order of its items in another list

2017-12-12 Thread Ray Miller
Very similar to your solution: (filter (set small-list) big-list)

On 12 December 2017 at 13:24, Deyan Yotsov  wrote:

> Hello,
>
> I have one list of potentially up to 2 million strings: big-list.
>
> Then I have another list, small-list, the elements of which are a subset
> of the elements of big-list.
>
> I want to sort the elements in small-list so that they become sorted in
> the same way in which they are sorted in big-list.
>
> The most obvious way to do this, for me, is:
>
> (filter #(some #{%} small-list) big-list)
>
> (one by one we take the elements from big-list, we check if they are in
> small-list, and if they are, we add them (in big-list order) to the result)
>
> But of course this performs extremely poorly, especially if small-list is
> say 1M elements, and big-list is 2M elements.
>
> Suggestions?
>
> Thank you,
>
> Deyan
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sorting a list based on the order of its items in another list

2017-12-12 Thread Deyan Yotsov

Thank you very much, Ray Miller and Gary Trakhman!


On 12/12/2017 02:32 PM, Ray Miller wrote:

Very similar to your solution: (filter (set small-list) big-list)

On 12 December 2017 at 13:24, Deyan Yotsov > wrote:


Hello,

I have one list of potentially up to 2 million strings: big-list.

Then I have another list, small-list, the elements of which are a
subset of the elements of big-list.

I want to sort the elements in small-list so that they become
sorted in the same way in which they are sorted in big-list.

The most obvious way to do this, for me, is:

(filter #(some #{%} small-list) big-list)

(one by one we take the elements from big-list, we check if they
are in small-list, and if they are, we add them (in big-list
order) to the result)

But of course this performs extremely poorly, especially if
small-list is say 1M elements, and big-list is 2M elements.

Suggestions?

Thank you,

Deyan

-- 
You received this message because you are subscribed to the Google

Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com

Note that posts from new members are moderated - please be patient
with your first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

--- You received this message because you are subscribed to the
Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to clojure+unsubscr...@googlegroups.com
.
For more options, visit https://groups.google.com/d/optout
.


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient 
with your first post.

To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google 
Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to clojure+unsubscr...@googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups "Clojure" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Loading deps.edn Dynamically in Clojure 1.9

2017-12-12 Thread Asim Jalis
Is it possible to load deps.edn dynamically without restarting the REPL in
Clojure 1.9?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: functional implementation of core.async primitives

2017-12-12 Thread Divyansh Prakash
Hi, @halgari! The JS port actually does have this, just haven't found the 
time to port it back.
But basically we can define something like:

(defn goloop*
>   [f initial-state]
>   (letfn [(recur+ [state]
> (goloop* f state))]
> (go
>   (f recur+ initial-state
>
>
> (defmacro goloop
>   [[var initial-state] & body]
>   `(goloop* (fn [~'recur+ ~var]
>   ~@body)
> ~initial-state))
>


 And then use it this way:

repl>
> (def ch (chan))
>
#'functional-core-async.core/ch

 
>
repl> 
>
(goloop [acc 0]
>   (go (if (not= :NIL v)
>   (recur+ (+ acc v))
>   (println "Count" acc
> #object[java.util.concurrent.ArrayBlockingQueue 0x3ddbadf5 "[]"] 
>
 
>
repl> 
>
(go>! [ch 1])
> #object[java.util.concurrent.ArrayBlockingQueue 0x28864bee "[]"]
>
 
>
repl>
> (go>! [ch 4])
> #object[java.util.concurrent.ArrayBlockingQueue 0x5caa5b10 "[]"]
>
 
>
repl>
> (go>! [ch :NIL])
> #object[java.util.concurrent.ArrayBlockingQueue 0x2d40473a "[]"]
> Count 5
>

- Divyansh 

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: functional implementation of core.async primitives

2017-12-12 Thread Divyansh Prakash
In fact, the JS implementation is much ahead of the Clojure version as of 
right now - with a better parking algorithm and `goconsume` for creating 
actors that park on read from a channel in an implicit loop.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: functional implementation of core.async primitives

2017-12-12 Thread Divyansh Prakash
Just remembered that I did give an example in the README, a port of 
braveclojure's hotdog machine.

(defn hot-dog-machine
>   [in out hot-dogs-left]
>   (when (> hot-dogs-left 0)
> (go   (if (= 3 input)
> (go>! [out "hot dog"]
>   (hot-dog-machine in out (dec hot-dogs-left)))
> (go>! [out "wilted lettuce"]
>   (hot-dog-machine in out hot-dogs-left))
>
>
(let [in (chan)
>   out (chan)
>   _ (hot-dog-machine in out 2)]
>   (>!! in "pocket lint")
>   (println (
>   (>!! in 3)
>   (println (
>   (>!! in 3)
>   (println ( wilted lettuce; => hotdog; => hotdog
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Loading deps.edn Dynamically in Clojure 1.9

2017-12-12 Thread Alex Miller
No, although there are a couple external projects along these lines ...

https://github.com/RutledgePaulV/clj-embed

And also people are poking on things like this in boot pods.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: functional implementation of core.async primitives

2017-12-12 Thread Divyansh Prakash
I just added `goloop` and `goconsume` to the Clojure implementation, with  
version of `recur` called `gorecur`.

*Example:*

> repl>
> (def ch (chan))
> #'functional-core-async.core/ch
>
> repl>
> (goconsume [v ch]
>   (if (= :ok v)
> (gorecur)
> (println "done")))
> #object[java.util.concurrent.ArrayBlockingQueue 0x30bb0ac9 "[[]]"]
>
> repl>
> (>!! ch :ok)
> nil
>
> repl>
> (>!! ch :ok)
> nil
>
> repl>
> (>!! ch :ok)
> nil
>
> repl>
> (>!! ch :nope)
> done
> nil
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Loading deps.edn Dynamically in Clojure 1.9

2017-12-12 Thread Sean Corfield
Yes, if you use Boot.

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

From: Asim Jalis
Sent: Tuesday, December 12, 2017 4:39 PM
To: clojure@googlegroups.com
Subject: Loading deps.edn Dynamically in Clojure 1.9

Is it possible to load deps.edn dynamically without restarting the REPL in 
Clojure 1.9?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.