Fork me on GitHub
#clojure
<
2016-08-15
>
amacdougall00:08:26

This is reasonable. Room contents, or even the state of devices such as switches and doors, could be associated with the static room somehow, rather than being nested within it.

amacdougall00:08:01

That would lead to a more decoupled design. And most of these things can be one-way lookups, room-id -> object. Only room-to-inhabitants and character-to-location are going to be two-way.

sgerguri00:08:24

Yeah, that's how I would probably do it, knowing what you wrote here, and being opinionated the way I am. I could, of course, be totally wrong about it.

amacdougall00:08:34

So while I'm fiddling around with nitty-gritty implementation details of map layout and traversal... any ideas about generating plausible maps from scratch given some requirements? This is a much more complex issue, but it's also very computer-sciency, so I bet there are papers I could read. For instance! Say I have a general idea for the zone: "city outskirts; to the east, a path through a jungle; somewhere in the jungle, a river path branches south to a village; meanwhile, the main path leads east to plains. At the heart of the plains, a temple." I'm envisioning a generator which can turn these vague instructions into a sequence of rooms, and even branch and backtrack after creating the river path and the village. Like, "we're in the jungle; we have generated four rooms already; the last room had a southeastern exit; we're -2 squares south, so we should err on the side of going northeast... oh wait, I passed the cumulative percent chance of generating the river path, so let's bookmark this point in the generation and start generating that branch."

sgerguri00:08:26

Also, if actions that happen within a room (characters updating health/stamina etc.) are more common than actions happening between rooms (characters transitioning) you may be better off using refs and having character state independent from their location.

devn00:08:29

A fun thing to do if you're interested, is to use Clara to write rules for a room/object/etc.

devn00:08:46

The rules engine

amacdougall00:08:47

This is relatively easy (ha), but when it comes to interconnected rooms, I'm stumped. For instance, a jungle path can be linear, but the plains should be a grid of interconnected rooms, to reflect the wide-open nature of it.

amacdougall00:08:00

But a sequential room generator doesn't allow for interconnections.

amacdougall00:08:37

I'll take a look at https://github.com/rbrush/clara-rules — it could have some good ideas.

devn00:08:46

Maybe it's just one tile

devn00:08:03

But you set a max n/e/s/w

devn00:08:20

And generate the contents over and over

amacdougall00:08:03

In the RPG combat system I'm envisioning, room movement is part of the tactical landscape: archers want to move one room away and start firing while the warrior blocks the exit to prevent enemies from chasing the archer, and so on. So the layout of the rooms will make different areas play very differently.

sgerguri00:08:07

Could be multiple, if you want to have a limited number of characters that fit in a given room.

amacdougall00:08:42

Loosely based on Avalon and the Iron Realms family of MUDs—showing my nerd credentials very clearly here. 😁

sgerguri00:08:03

Would abstracting the world as essentially a maze help? There are maze-generating algorithms that you could then use.

amacdougall00:08:48

@devn: That's a good idea, actually. The sequential generator can say "oh, this next part should have this shape," and it generates a set of rooms with a random but constrained shape.

devn00:08:09

@amacdougall: yeah that's kinda what I was thinking

devn00:08:17

Once you hit max of some direction

devn00:08:35

You can proceed to a new area

amacdougall00:08:43

@sgerguri: Yeah, the world is maze-like in the data-modelling sense. But by no means intended to befuddle...

amacdougall00:08:02

Yeah, sequential generator which can run subroutines. Makes sense to me.

amacdougall00:08:37

And I was thinking about limiting the number of characters per room, but then I'd have to think about the literal physical size of the room, which is probably out of scope for this toy project. Not hard to add later. A "room" in a sweeping plains could hold thousands of characters, but a closet in a castle could hold maybe four if they were good friends.

sgerguri00:08:43

There's a neat book from PragProg that could help with that - https://pragprog.com/book/jbmaze/mazes-for-programmers. The implementation language is Ruby but it makes for a fun project to transform the implementation from a mutable, object-based model into something purely FP. I started playing with that a while ago, reminds me I should get back to it when I next have a spare moment.

amacdougall00:08:07

Oh interesting! The title even suggests that it applies directly to my problem domain.

amacdougall00:08:35

...yes, I think this will be a great read. Thanks for the suggestion!

herbm00:08:30

Not directly relevant to question amacdoughall you might be interested in play-clj (there's a Clojure conj video on youtube)

herbm00:08:44

Different subject: This looks very interesting (and don't see it recommended many places): http://www.clojureatlas.com/

roberto00:08:31

anyone has any recommendations for a library for parsing xml?

roberto00:08:55

unfortunately I can’t find good docs for data.xml

dpsutton01:08:52

what information are you looking for, roberto?

roberto01:08:19

I want to be able to do something like: give me all tags

roberto01:08:47

trying to make sense of an api that returns xml (no docs about the structure of the document)

roberto01:08:39

and I’m also confused about clojure.xml and clojure.data.xml & clojure.zip & clojure.data.zip.xml

roberto01:08:16

their APIs look similar, yet different. Very confusing.

dpsutton01:08:59

well, found this, which is some documenation, which looks nice

dpsutton01:08:18

what function in the api returns "xml"?

roberto01:08:02

not sure I understand your question

dpsutton01:08:31

"trying to make sense of an api that returns xml". i don't know what you mean

roberto01:08:09

so I can read an xml string with (parse (java.ioByteArrayInputStream. (.getBytes xml-text))

roberto01:08:14

that returns a map

roberto01:08:47

yeah, I guess I just have to just eyeball this thing

dpsutton01:08:23

also, you might simplify it, if xml-text is a string, (parse-str xmltext), this also takes an encoding, which i think defaults to utf-8

dpsutton01:08:35

i recently ran into issues and had to specify "UTF-16"

holyjak08:08:15

@jiyinyiyong: Nice work! What I would really like would be (a short) blog post that introduces the motivation for this kind of the editor and highlights the main features. I am not really a video person 🙂

Jon10:08:13

@holyjak: thx, I will add the post later, also some quick start guides.

noobjure13:08:57

Is it recommended to learn to use nosql, mongodb or even basic SQL & etc before you try to approach Datomics as a beginner?

josh_tackett13:08:46

Does anyone know how to set up the database connection in this library: https://github.com/clojure/java.jdbc

josh_tackett13:08:00

(def mysql-db {:subprotocol "mysql"
               :subname "//127.0.0.1:3306/clojure_test"
               :user "clojure_test"
               :password "clojure_test”})

josh_tackett13:08:16

This is what I have, but I have a URL. That I have set to subname

yonatanel13:08:52

Is there already such a thing as map-invert-with which will map values to keys but will combine duplicate values with a function?

(defn map-invert-with [m f]
  (reduce (fn [m [k v]] (if (contains? m v)
                          (assoc m v (f (get m v) k))
                          (assoc m v k))) {} m))

lvh13:08:58

That looks awesome, I look forward to seeing how it’ll help me sell cljs in different portions of my company (we use it so far, but we get a lot of developer leeway)

amacdougall15:08:10

@danielcompton: Thanks for the advice earlier. Also, thanks for making https://therepl.net/ !

Jon15:08:24

@holyjak: here's the post. but I'm not into the details of the features actually, or it would be a lor longer(already mid-night in my timezone) https://medium.com/cirru-project/stack-editor-programming-by-functions-a961f1d9555c#.n76np9i1x

dpsutton16:08:32

I'll be honest, the lack of parens and non-uniform indentation really throws me off

dpsutton16:08:07

nor do i really understand what it means to not look at text but AST, since I kinda consider s-exp as AST's, but convenient and clearly delimited

Jon16:08:11

I see that as different tastes. I've been writing with this style for months and already into it.

dpsutton16:08:23

oh i understand that. just giving my initial reaction

Jon16:08:03

S-expressions is good enough for most people. Maybe I'm very special..

dpsutton16:08:33

i don't understand the difference, as the screenshot looks like text but with the delimters blanked out

Jon16:08:53

my editor is implemented with DOM, even it looks like text, it's still a tree. I just styled it to be less messy. It could be really messy with a lot of borders.

dpsutton16:08:57

I'm also wondering what (* (+ 1 2 3) 5) would look like in your editor. Without parens, variadic function calls would be ambiguous?

dpsutton16:08:39

you could write * + 1 2 3 4 5 which could obviously be parsed as many expressions, * (+ 1 2 3 4 5) => 15, all the way down (* (+) 1 2 3 4 5) => 0

dpsutton16:08:53

oh it underlines

dpsutton16:08:06

does that span multiple lines well?

Jon16:08:23

there's an algorithm tweaking the style for me.

Jon16:08:56

"span multiple lines" what does it mean, any example for that?

dpsutton16:08:15

the parens in this example show that 3 is the last argument to + and 4 is the last argument to *, but if you required underlining to see this, I'm just wondering what that looks like when it spans multiple lines

Jon16:08:27

oh, the algorithm will keep them in a single line.

dpsutton16:08:04

just thinking of things offhand. it looks really nice

dpsutton16:08:24

also i like the idea of showing you what's relevant rather than what's adjacent, re your organizing according to call stack

dpsutton16:08:24

why did you go back to the plus after you entered the 3?

Jon16:08:30

I should make GIF.... it would would much better to see it in action, as the algorithm auto layout my code

dpsutton16:08:36

do you have to go to the beginning of an expression to delimit it?

Jon16:08:54

it's actually "(* (+ 1 2 3)" at that moment, I was moving to the ")", which is invisible, so the corresponding "(" is highlighted

Jon16:08:33

last demo on the layout algorithm, going to bed... https://youtu.be/g0tAVjwuc1U

borkdude18:08:52

How does one make a qualified keyword using the current namespace, without double colon?

borkdude18:08:42

(keyword (str *ns*) "bar")
?

dpsutton18:08:52

can you get from the current ns?

hiredman20:08:45

watch out using ns

hiredman20:08:57

*ns* is exposed compiler state. in the repl is sort of a mish mash of compilation and runtime, but if you are just running code without a repl, the value of *ns* is likely to be something different from what you got in the repl

dpsutton20:08:50

tried this monstrosity and still no luck

dpsutton20:08:10

figured that would kick back a keyword from a different namespace, and therefore be fully qualified

dpsutton20:08:15

the only luck i'm getting is putting a function in the namespace you want qualified and returning a qualified keyword.

dpsutton20:08:57

so in core, having (defn f [] ::bob) and then in core.test

hiredman20:08:53

or just write out the namespace

hiredman20:08:02

what are you trying to do?

dpsutton20:08:09

ha i don't know why i didn't think of that. i just saw borkdude mention he was trying to get qualified keywords without using a double colon so i was trying to see what i could come up with

dpsutton20:08:12

i honestly don't know

mbertheau20:08:01

@steveb8n: Is your talk at cljsyn referenced in https://github.com/Day8/re-frame/blame/develop/CHANGES.md#L87 recorded and available online? Or slides?