Tag Info

Hot answers tagged

46

The answer seems to be yes. At least, I will try to describe an attempt which would pass the "under 100 lines of code" test. How well it satisfies the other criteria is a subjective matter, but I have already used it for larger-scale project with so far very positive results. I will present two implementations. One is an absolute toy, but extremely simple. ...


16

I know this thread is old and that Leonid provided a great solution, but I'd like to present a bit different approach. My approach is inspired by JavaScript. There are no classes, just "pure objects". To directly answer requirements from question Support instantiation, inheritance and polymorphism. Objects are fully dynamic, everything can be changed in ...


12

Another, shorter way is Append[d, t] From the docs, DateObject[date,time] represents the specified date list and TimeObject time. If you need the list you mention in the question, just convert the DateObject using DateList: DateList@Append[d, t] (* {2012, 6, 11, 14, 1, 45.} *)


4

I believe the crux of your problem is, as you say, how to match n_NewHead. Let's look at the FullForm: FullForm[n_NewHead] Pattern[n, Blank[NewHead]] As you can see this is composed of Blank and Pattern, both of which are special heads with regard to pattern matching. You therefore need to wrap them in Verbatim to make a literal match: MatchQ[ ...


3

Strip off their heads. replace them with List and then Flatten them: dt=DateObject@@(List @@@ {d, t} // Flatten) DateObject[{2012, 6, 11, 14, 1, 45.}] Or .... dt=DateObject @@ Join @@ {d[[1]], t[[1]]}


1

I don't understand why you need this functionality. If you really need Part to write to your object, then again, I suggest you use one of the ways of simulating OOP in MMA (see my linked question in comments). You ask if instead there is a simpler, more obvious approach. I think that all you really need is the following: ContiguousOrderedIntegerMap /: ...



Only top voted, non community-wiki answers of a minimum length are eligible