I've written a (array) container class template (lets call it smart array) for using it in the BREW platform (which doesn't allow many C++ constructs like STD library, exceptions, etc. It has a very minimal C++ runtime support); while writing this my friend said that something like this already exists in Boost called MultiArray, I tried ...
Base question:
Why can I write in Scala just:
println(10)
Why don't I need to write:
Console println(10)
Followup question:
How can I introduce a new method "foo" which is everywhere visible and usable like "println"?
...
This is what I've got, but it also finds classes and other constants.. is there a better way?
class Module
def children
constants.collect { |c| const_get(c) }.compact
end
end
...
We have a need to create SQLAlchemy classes to access multiple external data sources that will increase in number over time. We use the declarative base for our core ORM models and I know we can manually specify new ORM classes using the autoload=True to auto generate the mapping.
The problem is that we need to be able generate them dy...
Hi,
I was thinking about a typical problem that is very JIT-able, but hard to approach with raw C. The scenario is setting up a series of function pointers that are going to be "composed" (as in maths function composition) once at runtime and then called lots and lots of times.
Doing it the obvious way involves many virtual calls, that...
im looking into mongoengine, and i wanted to make a class an "EmbeddedDocument" dynamically, so i do this
def custom(cls):
cls = type( cls.__name__, (EmbeddedDocument,), cls.__dict__.copy() )
cls.a = FloatField(required=True)
cls.b = FloatField(required=True)
return cls
A = custom( A )
and tried it on some classes, bu...
how do i add code to an existing function, either before or after?
for example, i have a class:
class A(object):
def test(self):
print "here"
how do i edit the class wit metaprogramming so that i do this
class A(object):
def test(self):
print "here"
print "and here"
maybe some way of appendi...
Tim Sweeney of Epic MegaGames is the lead developer for Unreal and a programming language geek. Many years ago posted the following screen shot to VoodooExtreme:
As a C++ programmer and Sweeney fan, I was captivated by this. It shows generic C++ code that implements some kind of scripting language where that language itself seems to b...
This is a large commit. But I want you to concentrate on this change block. http://github.com/rails/rails/commit/d916c62cfc7c59ab6411407a05b946d3dd7535e9#L2L1304
Even without understanding the full context of the code I am not able to think of a scenario where I would use
include Module.new {
class_eval <<-RUBY
def foo
pu...
If I want to write my engine which will generate all the code solving the task described in simple declarative style, what languages should I look at?
...
As I've found myself repeating myself a lot, writing very similar queries and classes for different entities (despite of doing strong object and relational normalisation), etc, I've came to an Idea that I could and should automate the most of this and write an engine which will compile simple declarative models I specify into all the cod...
Guys, I've just dipped in to limits.h by MS. I tried to check what's the return type for max() fnc and to my surprise I see something like this:
// TEMPLATE CLASS numeric_limits
template<class _Ty>
class numeric_limits
: public _Num_base
{ // numeric limits for arbitrary type _Ty (say little or nothing)
public:
sta...
I'm studying Ruby and my brain just froze.
In the following code, how would I write the class writer method for 'self.total_people'? I'm trying to 'count' the number of instances of the class 'Person'.
class Person
attr_accessor :name, :age
@@nationalities = ['French', 'American', 'Colombian', 'Japanese', 'Russian', 'Peruvi...
I have the following program.
module C
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def test_for
class_eval <<-DEFINECLASSMETHODS
def self.my_method(param_a)
puts "SELF is: #{self.inspect}"
puts param_a
puts "#{param_a}"
end
DEFINECLAS...
This is as far as I've gotten,
#include <boost/mpl/list.hpp>
#include <algorithm>
namespace mpl = boost::mpl;
class RunAround {};
class HopUpAndDown {};
class Sleep {};
template<typename Instructions> int doThis();
template<> int doThis<RunAround>() { /* run run run.. */ return 3; }
template<> int doThis<HopUpAndDown>() { /* hop ho...
Is it possible to use member function pointers with template meta-programming? Such as:
class Connection{
public:
string getName() const;
string getAlias() const;
//more stuff
};
typedef string (Connection::*Con_Func)() const;
template<Con_Func _Name>
class Foo{
Connection m_Connect;
public:
Foo(){
cout << (m_...
I have a bunch of methods like this in view helper
def background
"#e9eaec"
end
def footer_link_color
"#836448"
end
I'd like these methods exposed to the view, but I'd prefer the helper to be a bit more concise. What's the best way to turn a hash, say, into methods (or something else)?
...
In the following Groovy snippet, I attempt to replace both the hashCode and toString methods
String.metaClass.toString = {-> "override" }
String.metaClass.hashCode = {-> 22 }
But when I test it out, only the replacement of hashCode works
String s = "foo"
println s.hashCode() // prints 22
println s.toString() // prints "foo"
Is to...
What's the best language (in terms of simplicity, readability and code elegancy) in your opinion, to learn and work with metaprogramming?
I think metaprogramming is the "future of coding". Not saying that code will extinct, but we can see this scenario coming on new technologies.
...
Is there anyway in C# to call a method based on a Enum and/or class?
Say if I were to call
Controller<Actions.OnEdit, Customer>(customer);
Could I do something like this then?
public void Controller<TAction, TParam>(TParam object)
{
Action<TParam> action = FindLocalMethodName(TAction);
action(object);
}
private Action<T> Fi...