Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Problem with this in object literals #103

Closed
2 tasks done
jcubic opened this issue Dec 12, 2020 · 1 comment
Closed
2 tasks done

Problem with this in object literals #103

jcubic opened this issue Dec 12, 2020 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@jcubic
Copy link
Owner

jcubic commented Dec 12, 2020

this in lambdas is environment object, but this is problematic because it don't work on objects literals:

lips> ((. (object :foo (lambda () this)) 'foo))
#<environment>
lips> (define x (object :foo (lambda () this)))
lips> (x.foo)
#<environment>
lips> (new (lambda () this))
#<instance>

so it only work on new operator. It would be nice if it works on any objects.

  • Find a fix
  • Unite tests functions that use this to get another function from env in this like for-each
@jcubic jcubic added the bug Something isn't working label Dec 12, 2020
@jcubic
Copy link
Owner Author

jcubic commented Dec 17, 2020

Even in class methods this is environment.

(let* ((a (class Object
                 (constructor (lambda (self)
                              (print this)
                              (set! self.x '(1 2 3))))
                 (run (lambda (self)
                        (print this)
                        (for-each print self.x)))))
       (b (new a)))
  (b.run))
#<environment>
#<environment>
1
2
3

Maybe solution would be to always use self and not document this at all.

this is werid:

lips> (new (lambda () (print this) (for-each print '(1 2 3))))
#<lambda>
1
2
3
#<instance>

for-each use this to get instance of map, but this is not a problem.

And this:

lips> (define x (object :foo (lambda () this)))
lips> (x.foo.call x)
&(:foo #<procedure>)

The problem may be that the function is unbind before call.

jcubic added a commit that referenced this issue Dec 17, 2020
Fix repr of this when new lambda (it's now properly identiefied as instance)
@jcubic jcubic closed this as completed Dec 17, 2020
jcubic added a commit that referenced this issue Dec 17, 2020
jcubic added a commit that referenced this issue Dec 18, 2020
@jcubic jcubic added this to the 1.0 milestone Dec 22, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant