Skip to content

Instantly share code, notes, and snippets.

View vporton's full-sized avatar

mathematician vporton

View GitHub Profile
```d
import std.stdio;
struct S {
void f2(int i) {}
}
void main(string[] args)
{
S s;
origin git@github.com:vporton/DIPs.git (fetch)
origin git@github.com:vporton/DIPs.git (push)
upstream git@github.com:dlang/DIPs.git (fetch)
upstream git@github.com:dlang/DIPs.git (push)
2019-02-24 19:40 Michael Parker o {origin/master} {origin/HEAD} [1018] Add link to implementation PR
2019-02-24 19:40 Michael Parker o [1018] Finalize reviews
2019-02-24 19:34 Michael Parker o Update 1018 status in DIPs readme
2019-02-24 19:33 Michael Parker o [1018] Move to accepted dir
2019-02-24 19:32 Michael Parker o [1018] Update based on Walter's feedback
2019-02-24 19:30 Michael Parker o [1018] Add community review summary
2019-02-15 21:54 Michael Parker o [1019] Move from DIPS to DIPs
2019-02-15 21:50 Michael Parker o Add DIP 1019 in Community Review
2019-02-15 12:28 yshui o [New DIP] Named arguments lite (#123)
2019-01-30 23:00 Michael Parker o [1017] Mark as rejected.

Passing parameters through structs with nullable fields

The problem

Sometimes we need to combine an aggregate of a set of values with an aggregate of the corresponding set of default values to create a combined result. The result for each member is either the explicitly specified value or, where no value is specified, the default value. This is similar to default function arguments in D (however, D forces one to always specify the first N values in function parameters, while I want to be able to specify an arbitrary subset of the values).

Example:

Explicit values: a: 1, b: 2

Memoization in the D Programming Language, part 2

In continuation of the article Memoization in the D Programming Language, this article describes new features of my D library memoize-dlang.

I remind that memoization is automatically not calling a function again when called with the same parameters (usually to reduce the amount of computations).

memoize functions

memoize is the same as memoize from std.functional module from standard library Phobos (implemented differently in some very little details, namely using string mixins (autogenerated code) to implement all of memoize, noLockMemoize, synchronizedMemoize (see below) based on a common template). memoize template without maxSize argument is implemented in a quite simple way (see below). memoize with maxSize argument is implemented in a rather comple

Modify tuple modifiers

The problem

In the standard D library it seems missing a function to modify tuple modifiers.

Consider the following:

alias t = AliasSeq!(int, float); // create tuple (int, float) of two types
alias tc = addTupleModifiers!("const shared", t);

In D language we cannot construct an object of a template argument type in a template, as shown by the following example:

class Constructor(Result, Params...) {
    const(Result) create(Params params) {
        return new Result(params);
    }
}

void main() {
    class X { }

Pure Dependency Injection in D

Dependency injection

A little modified quote from Wikipedia, Dependency injection article (This quote is licensed under CC BY-SA 3.0):

In software engineering, dependency injection is a technique whereby one object (or static method) supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. The service is made part of the client's state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.

The intent behind dependency injection is to achieve Separation of Concerns of construction and use of objects.

        private static void ProcessTable(ModelBuilder modelBuilder, PropertyInfo contextMember)
        {
            Type tableType = contextMember.PropertyType.GetGenericArguments()[0];

            PropertyInfo[] members2 = tableType.GetProperties();

            foreach (var m in members2)
            {
                object[] attrs = m.GetCustomAttributes(typeof(KeyAttribute), true);
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace BravoDB.Models.Tables
{
[Table("AdvShows")]
public class AdvShowsTable
{
[Key]
public int AdvOrderID { get; set; }