This seems hard to make sane in a dynamic language. The issue is that `foo`
doesn't give you enough information at compile time to decide which names
are fields of `foo` and which are just local variables. If the first
argument to the @with macro had to be a name of a type – i.e. Foo rather
than foo – then you could do it. You could loosen that up to allow any
expression that can be evaluated at compile time in the global scope where
the @with occurs, but that seems pretty confusing. For example, you
couldn't write `@with typeof(foo)` which is pretty much the first thing
that people will try to do.

On Thu, May 21, 2015 at 9:13 AM, Magnus Lie Hetland <[email protected]> wrote:

> A couple of decades ago, I remember using the with statement in Pascal. I
> have since wished for it in several languages, but I guess in Julia, it
> would probably be feasible without altering the language?
>
> Basically, it'd be something like
>
> type Foo
>     a
> end
>
> foo = Foo(42)
>
> @with foo do
>     a = 1
>     b = "frozzbozz"
>     # ...
> end
>
> # foo.a is now 1
>
> That is, let the fields of a composite type be available (syntactically)
> as local variables.
>
> Now, hacking together something like this wouldn't be hard – but making it
> really work (without weirdness or performance degradation) seems harder.
> And maybe it's a bad idea to begin with. Or maybe someone has already done
> it?-)
>
>
>
>

Reply via email to