Fork me on GitHub
#beginners
<
2015-07-31
>
surreal.analysis14:07:54

Is there a function or macro that takes a vector and returns the elements of that vector?

surreal.analysis14:07:05

e.g. I have [[1 2] [3 4]]

surreal.analysis14:07:11

And I want [1 2] [3 4]

potetm14:07:38

@surreal.analysis: How can a function return multiple things?

surreal.analysis14:07:59

I should say just a macro

potetm14:07:13

I tend to destructure that out

potetm14:07:05

(let [[one-and-two three-and-four] [[1 2] [3 4]]] …)

surreal.analysis14:07:23

In many Clojure libraries, e.g. Hiccup, Reagent, clj-pdf, vectors are used to represent the data

surreal.analysis14:07:32

In my case, I am using clj-pdf

potetm14:07:14

In both Hiccup and Reagent, you have to pass them a single data structure, and they return a single data structure.

surreal.analysis14:07:46

I suppose my issue is, right now, I’m not sure what that data structure would be in clj-pdf

surreal.analysis14:07:56

As far as I can tell, there is no div equivalent

surreal.analysis14:07:14

So what I would like is essentially three or four data structures in a row

surreal.analysis14:07:21

And I’m not sure how to group them

surreal.analysis14:07:32

But perhaps I’m just misusing the library

potetm14:07:56

Yeah, I’m not sure exactly what you’re trying to do. I would need a specific example.

potetm14:07:17

For example, I remember once that I wanted a function that returns all of the :lis for a :ul, so what you’re saying would be useful. But it turned out that I was thinking about it wrong. I needed to have the thing generating the :ul create all of the :lis.

surreal.analysis15:07:19

I agree, I’m almost certainly thinking about it incorrectly

surreal.analysis15:07:24

But I’m not sure how to thing about it correctly simple_smile

surreal.analysis15:07:41

And I want to do something pretty similar to that

surreal.analysis15:07:46

Except, instead of returning a paragraph

surreal.analysis15:07:54

I want to generate a PDF table and a paragraph

surreal.analysis15:07:24

So my employee-template looks more like

(template 
  [:pdf-table …]
  [:paragraph …]
)

surreal.analysis15:07:33

Now, that’s wrong, because template takes 1 argument

surreal.analysis15:07:44

So my first path towards solving this issue was wrapping it in a vector

surreal.analysis15:07:21

(template
    [[:pdf-table ..]
     [:paragraph ..]]
)

surreal.analysis15:07:03

Thinking that if I had that, I could make it work from there

surreal.analysis15:07:07

Which prompted the original question

upgradingdave18:07:01

Hi all, am I using trampoline correctly here?

upgradingdave18:07:38

I’m trying to wrap my head around recursion in functional style languages and how to use trampoline so there’s no stackoverflow

upgradingdave18:07:47

in this example, I’m trying to convert a tree like structure like {:a {:b “1” :c “2”}} into something like [[:a :b “1”] [:a :c “2”]]

potetm21:07:19

@surreal.analysis: Sorry for taking all day. Got caught up.

potetm21:07:44

Yeah, the accepted answer to that stackoverflow question pretty much sums up what I was saying.

potetm21:07:36

Regarding your issue, so you want a function that returns a table followed by a paragraph?

potetm21:07:24

If they’re siblings and can’t be wrapped, I don’t know of any other way besides specifying them side-by-side. However, if that’s the case, I would question whether or not they truly need to be abstracted away.

surreal.analysis21:07:22

@potetm: Yes, they are siblings

surreal.analysis21:07:47

re: using a template, the benefit of the template is that templates can easily be applied to collections

surreal.analysis21:07:17

I ended up fixing it by wrapping them in a pdf-table

surreal.analysis21:07:22

But that’s kind of ugly

surreal.analysis21:07:26

Because it’s not really a table

potetm21:07:33

@surreal.analysis: And there’s no kind of container for this whole thing?

surreal.analysis21:07:41

Not to the best of my knowledge

potetm21:07:01

so you have a list of things that are: [:table][:paragraph]. There has to be some kind of parent….

potetm21:07:19

Like pdf or something

surreal.analysis21:07:58

pdf is a function (or macro) that takes a vector of elements

potetm21:07:48

So you could do (pdf (mapcat (fn [child] [[:table][:paragraph]]) children)?

surreal.analysis21:07:48

Thanks, that pointed me enough in the right direction

surreal.analysis21:07:55

Something like that might work

surreal.analysis21:07:58

But what I ended up doing

surreal.analysis21:07:11

Is having the template return a vector

surreal.analysis21:07:28

of [[:table] [:paragraph]]

surreal.analysis21:07:39

And then just applied concat to that

potetm21:07:46

That’ll do!

potetm21:07:53

not a prob simple_smile