Search Results

Search found 968 results on 39 pages for 'lambda'.

Page 23/39 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • What are the benefits of using Boost.Phoenix?

    - by Denis Shevchenko
    Hello all! I can not understand what the real benefits of using Boost.Phoenix. When I use it with Boost.Spirit grammars, it's really useful: double_[ boost::phoenix::push_back( boost::phoenix::ref( v ), _1 ) ] When I use it for lambda functions, it's also useful and elegant: boost::range::for_each( my_string, if_ ( '\\' == arg1 ) [ arg1 = '/' ] ); But what are the benefits of everything else in this library? The documentation says: "Functors everywhere". I don't understand what is the good of it?

    Read the article

  • Palindrome Golf

    - by Claudiu
    The goal: Any language. The smallest function which will return whether a string is a palindrome. Here is mine in Python: R=lambda s:all(a==b for a,b in zip(s,reversed(s))) 50 characters. The accepted answer will be the current smallest one - this will change as smaller ones are found. Please specify the language your code is in.

    Read the article

  • PLT Scheme sort function

    - by Danny
    PLT Scheme guide says that it's implemented sort function is able to sort a list according to an extarcted value using a lambda function. link text The guide provides an unworking code example of this- (sort '(("aardvark") ("dingo") ("cow") ("bear")) #:key car string<?) Which returns an error. How is this function is supposed to be calles so that it will actually sort a list according to values calculated by a given function?

    Read the article

  • will_paginate with named_scopes

    - by Lowgain
    I'm using will_paginate for pagination, which has been working well so far, except for this one thing. If I try to paginate a scope, for instance class User < ActiveRecord::Base named_scope :scope, lambda { etc } end User.scope.paginate({:page => params[:page], :per_page => 10}) That will tell me paginate is an undefined method. I'd rather not have to use a second solution for only this scope, is there something I can do here?

    Read the article

  • Dynamic URL -> Controller mapping for routes in Rails

    - by Daniel Beardsley
    I would like to be able to map URLs to Controllers dynamically based on information in my database. I'm looking to do something functionally equivalent to this (assuming a View model): map.route '/:view_name', :controller => lambda { View.find_by_name(params[:view_name]).controller } Others have suggested dynamically rebuilding the routes, but this won't work for me as there may be thousands of Views that map to the same Controller

    Read the article

  • Derivative of a Higher-Order Function

    - by Claudiu
    This is in the context of Automatic Differentiation - what would such a system do with a function like map, or filter - or even one of the SKI Combinators? Example: I have the following function: def func(x): return sum(map(lambda a: a**x, range(20))) What would its derivative be? What will an AD system yield as a result? (This function is well-defined on real-number inputs).

    Read the article

  • Hidden features of C#3.5 [closed]

    - by xyz
    Possible Duplicate: Hidden Features of C#? Kindly donot mistake this question with Hidden Features of C#?. It is specific to C# 3.5 / dot net 3.5 I have figured out some(what I have used so far). They are as under 1) Linq 2(Objects, Sql, Xml) 2) Lambda expressions 3) Extention methods 4) Object initializers 5) Collection initialisers 6) Anonymous delegates 7)Automatic properties Please help me in finding out more. Thanks

    Read the article

  • Rails: three most recent comments with unique users

    - by Dennis Collective
    what would I put in the named scope :by_unique_users so that I can do Comment.recent.by_unique_users.limit(3), and only get one comment per user? class User has_many :comments end class Comment belongs_to :user named_scope :recent, :order => 'comments.created_at DESC' named_scope :limit, lambda { |limit| {:limit => limit}} named_scope :by_unique_users end on sqlite named_scope :by_unique_user, :group = "user_id" works, but makes it freak out on postgres, which is deployed on production PGError: ERROR: column "comments.id" must appear in the GROUP BY clause or be used in an aggregate function

    Read the article

  • Getting started with nbehave

    - by dotnetdev
    Hi, I am looking at using BDD, however, when evaluating the stories/conditions I write (using nBehave), how do I check if the story passes? Do I write another library with test methods? For example, if I want to test a site for having a link called "About", do I write a method which can check this and then another method in another class library which can call the method to check the link via lambda syntax and add the relevant test and bdd attributes? Thanks

    Read the article

  • Code hot swapping in Erlang

    - by Roger Alsing
    I recently saw a video about Erlang on InfoQ, In that video one of the creators presented how to replace the behavior of a message loop. He was simply sending a message containing a lambda of the new version of the message loop code, which then was invoked instead of calling the old loop again. Is that code hot swapping in Erlang reffers to? Or is that some other more native feature?

    Read the article

  • Rails: three most recent comments for unique users

    - by Dennis Collective
    class User has_many :comments end class Comment belongs_to :user named_scope :recent, :order => 'comments.created_at DESC' named_scope :limit, lambda { |limit| {:limit => limit}} named_scope :by_unique_users end what would I put in the :by_unique_users so that I can do Comment.recent.by_unique_users.limit(3), and only get one comment per user

    Read the article

  • twisted reactor stops too early

    - by pygabriel
    I'm doing a batch script to connect to a tcp server and then exiting. My problem is that I can't stop the reactor, for example: cmd = raw_input("Command: ") # custom factory, the protocol just send a line reactor.connectTCP(HOST,PORT, CommandClientFactory(cmd) d = defer.Deferred() d.addCallback(lambda x: reactor.stop()) reactor.callWhenRunning(d.callback,None) reactor.run() In this code the reactor stops before that the tcp connection is done and the cmd is passed. How can I stop the reactor after that all the operation are finished?

    Read the article

  • Translate C# code into AST?

    - by Erik Forbes
    Is it currently possible to translate C# code into an Abstract Syntax Tree? Edit: some clarification; I don't necessarily expect the compiler to generate the AST for me - a parser would be fine, although I'd like to use something "official." Lambda expressions are unfortunately not going to be sufficient given they don't allow me to use statement bodies, which is what I'm looking for.

    Read the article

  • Load Pymacs & Ropemacs only when opening a Python file ?

    - by Mtgred
    I use Pymacs to load Ropemacs and Rope with the following lines in my .emacs as described here. (autoload 'pymacs-load "pymacs" nil t) (pymacs-load "ropemacs" "rope-") It however slowdown the startup of Emacs significantly as it takes a while to load Ropemacs. I tried the following line instead but that loads Ropemacs everytime a Python file opened... (add-hook 'python-mode-hook (lambda () (pymacs-load "ropemacs" "rope-"))) Is there a way to perform the pymacs-load when opening a Python file but only if ropemacs and rope aren't loaded yet?

    Read the article

  • Lisp's "some" in Python?

    - by Mark Probst
    I have a list of strings and a list of filters (which are also strings, to be interpreted as regular expressions). I want a list of all the elements in my string list that are accepted by at least one of the filters. Ideally, I'd write [s for s in strings if some (lambda f: re.match (f, s), filters)] where some is defined as def some (pred, list): for x in list: res = pred (x) if res: return res return False Is something like that already available in Python, or is there a more idiomatic way to do this?

    Read the article

  • overwrite existing entity via bulkloader.Loader

    - by Ray Yun
    I was going to CSV based export/import for large data with app engine. My idea was just simple. First column of CSV would be key of entity. If it's not empty, that row means existing entity and should overwrite old one. Else, that row is new entity and should create new one. I could export key of entity by adding key property. class FrontExporter(bulkloader.Exporter): def __init__(self): bulkloader.Exporter.__init__(self, 'Front', [ ('__key__', str, None), ('name', str, None), ]) But when I was trying to upload CSV, it had failed because bulkloader.Loader.generate_key() was just for "key_name" not "key" itself. That means all exported entities in CSV should have unique 'key_name' if I want to modify-and-reupload them. class FrontLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Front', [ ('_UNUSED', lambda x: None), ('name', lambda x: x.decode('utf-8')), ]) def generate_key(self,i,values): # first column is key keystr = values[0] if len(keystr)==0: return None return keystr I also tried to load key directly without using generate_key(), but both failed. class FrontLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Front', [ ('Key', db.Key), # not working. just create new one. ('__key__', db.Key), # same... So, how can I overwrite existing entity which has no 'key_name'? It would be horrible if I should give unique name to all entities..... From the first answer, I could handle this problem. :) def create_entity(self, values, key_name=None, parent=None): # if key_name is None: # print 'key_name is None' # else: # print 'key_name=<',key_name,'> : length=',len(key_name) Validate(values, (list, tuple)) assert len(values) == len(self._Loader__properties), ( 'Expected %d columns, found %d.' % (len(self._Loader__properties), len(values))) model_class = GetImplementationClass(self.kind) properties = { 'key_name': key_name, 'parent': parent, } for (name, converter), val in zip(self._Loader__properties, values): if converter is bool and val.lower() in ('0', 'false', 'no'): val = False properties[name] = converter(val) if key_name is None: entity = model_class(**properties) #print 'create new one' else: entity = model_class.get(key_name) for key, value in properties.items(): setattr(entity, key, value) #print 'overwrite old one' entities = self.handle_entity(entity) if entities: if not isinstance(entities, (list, tuple)): entities = [entities] for entity in entities: if not isinstance(entity, db.Model): raise TypeError('Expected a db.Model, received %s (a %s).' % (entity, entity.__class__)) return entities def generate_key(self,i,values): # first column is key if values[0] is None or values[0] in ('',' ','-','.'): return None return values[0]

    Read the article

  • Can I create class properties during __new__ or __init__?

    - by 007brendan
    I want to do something like this. The _print_attr function is designed to be called lazily, so I don't want to evaluate it in the init and set the value to attr. I would like to make attr a property that computes _print_attr only when accessed: class Base(object): def __init__(self): for attr in self._edl_uniform_attrs: setattr(self, attr, property(lambda self: self._print_attr(attr))) def _print_attr(self, attr): print attr class Child(Base): _edl_uniform_attrs = ['foo', 'bar'] me = Child() me.foo me.bar #output: #"foo" #"bar"

    Read the article

  • extract/slice/reorder lists in (emacs) lisp?

    - by Stephen
    In python, you might do something like i = (0, 3, 2) x = [x+1 for x in range(0,5)] operator.itemgetter(*i)(x) to get (1, 4, 3). In (emacs) lisp, I wrote this function called extract which does something similar, (defun extract (elems seq) (mapcar (lambda (x) (nth x seq)) elems)) (extract '(0 3 2) (number-sequence 1 5)) but I feel like there should be something built in? All I know is first, last, rest, nth, car, cdr... What's the way to go? ~ Thanks in advance ~

    Read the article

  • Is OOP based on any branch of mathematics?

    - by ektrules
    I know relational databases are based on set-theory, functional programming is based on lambda calculus, logic programming is based on logic (of course :)), and now that I think of it; I'm not sure if imperative and generic programming is based on any particular branch of mathematics either.

    Read the article

  • Sorting Python list based on the length of the string

    - by prosseek
    I want to sort a list of strings based on the string length. I tried to use sort as follows, but it doesn't seem to give me correct result. xs = ['dddd','a','bb','ccc'] print xs xs.sort(lambda x,y: len(x) < len(y)) print xs ['dddd', 'a', 'bb', 'ccc'] ['dddd', 'a', 'bb', 'ccc'] What might be wrong?

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >