I would like to access objects through point chaining like object-oriented or pure functional languages

Hi Hello ~
I would like to access objects through point chaining like object-oriented or pure functional languages.

It’s been about 13 years since I started studying Clojure, and it’s been about 5 years since I started using it in practice. It would be really nice to be like hylang… Is there (object or instance attributes dot chain) library related to this in clojure or clojurescript?

It’s always a bit disappointing, and I’m getting tired of using it these days. The linguistic function is the strongest, but when I look at the code I wrote later, I can’t easily figure out what I’ve done.

Thanks gooday~.

If I understood the question correctly, maybe one of these forms are what you’re looking for:

1 Like

check out the . and .. special forms
https://clojure.org/reference/java_interop#_the_dot_special_form

1 Like

Can you give an example of “access[ing] objects through point chaining like […] pure functional languages”? I’m not sure what you mean by that so I’m not sure what to suggest by way of an answer…

functional monad. Chaining is an exception, that’s another matter to mention.
However

in OOP
instanceName.member
member (attribute variables, method)
(instance.var 3)
(instance.method [1 2 3])
simple approach

return instance and repeat so on.
(instance.method.method.method.method 1 2)

like other languages. A simple approach,
at the moment of execution
I wish there was such a tool that unfolds internally in the form of clojure parentheses.

Currently, the approaches of clojure oop members are too diverse. I understand that you’ve taken it this way to make sure the problem is solved, but I think it leaves room for a bit of obscurity in the code, as mentioned at the outset.

(. Class method .-member these types)
(doto~
(.Class member ~
(member Class
etc

I just wanted to avoid these things.
It’s so confusing, and it’s a bit cumbersome to interpret whenever a new API comes out. (It is true that accessibility is not that complicated if you actually work)
If this problem is solved,
The secret to the popularity of clojure, I think it will be helpful for future development.

I’m sorry, but I still don’t understand what you’re actually talking about.

I’m getting the impression you don’t want to use the language features that Clojure provides but I don’t understand what you want to use instead…

I’m not sure I understand all your examples, but it would be like so:

instanceName.member

(-> instanceName .member)

member (attribute variables, method)

I don’t understand this one, this is not a syntax I’ve seen anywhere.

(instance.var 3)

(-> instance .var 3)

Though I’m a bit confused, are you trying to assign 3 to the instance var? Or is var a method you call with 3 as the argument?

(instance.method [1 2 3])

(-> instance (.method [1 2 3]))

return instance and repeat so on
(instance.method.method.method.method 1 2)

(-> instance .method .method .method (.method 1 2))

You’re right that there’s a lot of different interop access, but you can just use -> in all cases.

Construct an instance:

(Instance. 1 2)

Get a member field:

(-> instance .member)

Call a method:

(-> instance .method)

Call a method with arguments:

(-> instance (.method 1 2))

Chain as normal:

(-> instance .method .method .member)

Also works with Clojure functions:

(-> structure function function (function 1 2))

And you can mix and match:

(-> instance .member function (Instance.) .method (.method 1 2) (function 3))

1 Like

https://search.nixos.org/options

I’m talking about a simple schema tree. i already know that a nested map takes over for legacy oop in clojure world.

What I’m trying to say is that if you can’t express the code readability, the complexity of the legacy oop syntax itself, and the chained syntax for the first function name, can’t you solve it?

By improving the internal oop type system, I felt the need for such an oop/api schema tree that did not use thread macros, so I wrote this article.

Around 2011-3 When I was learning clojure for a long time (Stuart Halloway swan book) I already knew that the clojure map replaced oop. (Now, fortunately, I was delighted to see that the bean object was created the way I wanted it to at the time like thinking. However, I was recently thinking of doing it myself to clean up oop interop(clojure & java interop).
for years ago im met nix provisiong. and The system I’ve been using for years
Looking at the schema for the Nix language, I felt great freedom and comfort.
now next GitHub - tweag/nickel: Better configuration for less
In fact, this language is also a kind of oop with a function attached to the key in the json map.
Then name access is like static variable access.
a.b.c In this way, you can easily unpack and enter objects.
So, like in 2012-3, we catch this point and dont let it be. so I wrote this article with my attachment to clojure. ( is not war about monad & pure function language)
.
anyway little bit other perspec story but related.
Among the js libraries I want to use, there is a library called rhino3dm. From the beginning, the instance returns a promise object. (I can’t remember very well. In the past, there was an inconvenience of having to set get by catching the change time of all promise objects with stm atom hooking. I can’t remember where I left the code, I can’t find it. Just a clojure user. It’s just a pattern that people like to deal with atoms)
.
Anyway, I deal with different languages ​​and the main language is clojure, but the reason why I can’t get out of the beginner’s
I see it as a complex Legacy Oop syntax problem.

To simplify such a legacy oop in other languages,
We will need the Naming expander above,
.
Next thing to we do…
.
Declarative macros? or homoiconcity datastructure.
.
This is a code I wrote for fun while studying about 8 years ago.

There were times when I felt like maybe monad, but I forgot about that.

in nix

rec { <--- This allows rec to access with different name / recursion.
  a ={ b=3; }
  c = { d = a.b; }
}

There seems to be value in using this as @. (Do not write everything above like let.)

(rec {
  (setv a { b 3 } )
  (setv f #(+ 1 %))
  (setv c { d @a.b { e @@a.b f @d  g (@@f 2) } })
})

But
If @ is allowed in the definition, it’s messy, so a slightly different example.

(class A{ <--------------- Actually, it is better not to have rec (if it is declarative code anyway), and substitute/trap in front of it to declare a virtual class A
  (setv a { b 3 } )
  (setv c { (d a.b) { (e a.b) } })
  (setv f #static ...)
})

@ is used after instancing.
The @ keyword is more conspicuous when used in instance code as we use it in atom maps.
(However, when I first saw @, it was like c pointer variable operation as in the screenshot, but I had been thinking about where to use it for a long time (8 years…). after nix experience, As above, I thought it could be used in legacy oop definition like schema? functional languages, so clojure developers wondered if this is what we should go to.)

(-> (A) (@c.d).e )
(-> (B (A)) ...) < ----------- B accepts A instance as a constructor function, and B instantiates it immediately.

Just my personal imagination.
Of course, the class example definition shown there.
I thought it was necessary to aim for a class 1:1 definition between java for jvm languages.
all. (Unified simplicity)

Even if there were such a thing, I wouldn’t be an dumb not to use the basic nice functional features of clojure. But Java or JavaScript? typescript? etc… I think the story is slightly different in the case of interaction. Like hylang, 1:1 matching of dot names is essential. (And it is understandable that everyone asks why such expressions are needed in the value returned to method chaining about the sorry about that would my Mistakes in my stupid thinking. Please understand. :slight_smile:
So
It’s a nonsensical code, but I think it will maximize the value of clojure.
thanks.

Hey, so I’m not totally following everything, I think maybe a bit of a language barrier, but if I understood, I think you might be looking for something like this library perhaps?

You can then use it as such:

(rmap! {
  :a {:b 3}
  :f #(+ 1 %)
  :c (rmap!
       {:d (-> (ref :a) :b)
        {:e (-> (ref :a) :b)
         :f (ref :d)
         :g (@@f 2)}}) ;; This I'm not sure is supported with that library
})

It should get you close. I think it could also be you build a similar lib that’s even more like what you have, I guess it’s missing that nesting support and specifying what level on the outer map you want to refer too.

2 Likes

@didibus That’s right. Cool~

After seeing c# oop 10 years ago…, thinking about compared the two by looking at the c pointer operator.
and so I thought of that drawing while looking at the clojure map.
Naturally, the emotions below like are also filled with anticipation with that picture mind.
so Someday clojure~~~, after dot chaining comes in
Just coding with clojure map, It would be great if there was an easy way to spit fire the oop class with java or javascript.

@ is in the ← direction back one step to the original root,
The dot notation is the explicit name.name.name → direction.
.


{ A? A }:
{
inherit (A) B a b; <-------- this mean get-name A.B A.a A.b
inherit (A.B) C;
 f = 3;
}

So finally map is contains name { B, a, b, C, f }

------------------------------------- clojure

[b local-value]
{
   (inherit A [B a b]) <------- or (inherit (@b) [B a b])
   (inherit (A.B) [C] ) < --------- or (inherit (@b) [B.C])
  (def f 3)
}

so Finally map would contains Keys { B a b C f }

@ and . the direction was reversed (with picture & example code) , but
nix is . exists (The clojure has an @ difference direction chain)

Anyway, this is a pleasant imaginary memory trip ~
Busy again…,
studying nodejs (nbb is good) and java&clojure lol

:))

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.