Skip to content
Snippets Groups Projects
Select Git revision
  • poly1305
  • master default
  • support_pre_UAL_arm_asm
  • skein
  • rsa-crt-hardening
  • chacha96
  • fat-library
  • versioned-symbols
  • curve25519
  • dsa-reorg
  • aead-api
  • set_key-changes
  • aes-reorg
  • nettle-2.7-fixes
  • size_t-changes
  • ecc-support
  • experimental-20050201
  • lsh-1.4.2
  • nettle_3.3_release_20161001
  • nettle_3.2_release_20160128
  • nettle_3.1.1_release_20150424
  • nettle_3.1_release_20150407
  • nettle_3.1rc3
  • nettle_3.1rc2
  • nettle_3.1rc1
  • nettle_3.0_release_20140607
  • nettle_2.7.1_release_20130528
  • nettle_2.7_release_20130424
  • nettle_2.6_release_20130116
  • nettle_2.5_release_20120707
  • converted-master-branch-to-git
  • nettle_2.4_release_20110903
  • nettle_2.3_release_20110902
  • nettle_2.2_release_20110711
  • nettle_2.1_release_20100725
  • camellia_32bit_20100720
  • nettle_2.0_release_20090608
  • nettle_1.15_release_20061128
38 results

des-compat.c

Blame
  • Forked from Nettle / nettle
    Source project has a limited visibility.
    Function.pmod 3.15 KiB
    #pike __REAL_VERSION__
    
    constant defined = __builtin.function_defined;
    
    //! Calls the given function with the @[args] array plus the optional
    //! extra arguments as its arguments and returns the result.
    //!
    //! Most useful in conjunction with @[map], and particularly in combination
    //! with @[sscanf] with @expr{"...%{...%}..."@} scan strings (which indeed
    //! was what it was invented for in the first place).
    //!
    //! @param args
    //!  The first arguments the function @[f] expects.
    //! @param f
    //!  The function to apply the arguments on.
    //! @param extra
    //!  Optional extra arguments to send to @[f].
    //! @returns
    //!  Whatever the supplied function @[f] returns.
    //!
    //! @example
    //! @code
    //!   class Product(string name, string version)
    //!   {
    //!     string _sprintf()
    //!     {
    //!       return sprintf("Product(%s/%s)", name, version);
    //!     }
    //!   }
    //!   map(({ ({ "pike",   "7.1.11" }),
    //!          ({ "whitefish", "0.1" }) }),
    //!       Function.splice_call, Product);
    //!   ({ /* 2 elements */
    //!	 Product(pike/7.1.11),
    //!	 Product(whitefish/0.1)
    //!   })
    //! @endcode
    mixed splice_call(array args, function f, mixed|void ... extra)
    {
      return f(@args, @extra);
    }
    
    
    //! The dreaded fixpoint combinator "Y".
    //!
    //! The Y combinator is useful when writing recursive lambdas.  It
    //! converts a lambda that expects a self-reference as its first argument
    //! into one which can be called without this argument.
    //!
    //! @example
    //! This example creates a lambda that computes the faculty function.
    //! @code
    //!   Function.Y(lambda(function f, int n) { return n>1? n*f(n-1) : 1; })
    //! @endcode
    function Y(function f)
    {
      return lambda(function p) {
    	   return lambda(mixed ... args) {
    		    return f(p(p), @args);
    		  };
    	 } (lambda(function p) {
    	      return lambda(mixed ... args) {
    		       return f(p(p), @args);
    		     };
    	    });
    }
    
    
    //! Partially evaluate a function call.
    //!
    //! This function allows N parameters to be given to a function taking
    //! M parameters (N<=M), yielding a new function taking M-N parameters.
    //!
    //! What is actually returned from this function is a function taking N
    //! parameters, and returning a function taking M-N parameters.
    //!
    //! @example
    //! This example creates a function adding 7 to its argument.
    //! @code
    //!   Function.curry(`+)(7)
    //! @endcode
    function(mixed...:function(mixed...:mixed|void)) curry(function f)
    {
      return lambda(mixed ... args1) {
    	   return lambda(mixed ... args2) {
    		    return f(@args1, @args2);
    		  };
    	 };
    }
    
    
    //! Call a callback function, but send throws from the callback
    //! function (ie, errors) to master()->handle_error.
    //! Also accepts if f is zero (0) without error.
    //!
    //! @example
    //! @code
    //!   Functions.call_callback(the_callback,some,arguments);   
    //! @endcode
    //! equals 
    //! @code
    //!   {
    //!      mixed err=catch { if (the_callback) the_callback(some,arguments); };
    //!      if (err) master()->handle_error(err);
    //!   }
    //! @endcode
    //! (Approximately, since call_callback also calls handle_error
    //! if 0 were thrown.)
    void call_callback(function f,mixed ... args)
    {
       if (!f) return;
       mixed err=catch { f(@args); return; };
       handle_error(err);
    }
    
    function handle_error = master()->handle_error;