Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8985053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:15:09+00:00 2026-06-15T21:15:09+00:00

I am currently learning D and are taking the baby steps, so please bear

  • 0

I am currently learning D and are taking the baby steps, so please bear with me.

I am reading the book simply titled “The D Programming Language”. I am using the D-IDE for my code. I am currently writing a program, which is supposed to add words to it’s vocabulary (dictionary) if the book doesn’t already have the word.

The problem is though, that the code the book provides is invalid, and instead of just moving on and reading what the results should be etc. I wanted to try and solve it. Of course a problem that I am so new to D.

The code looks as such:

import std.stdio, std.string;

void main() {
    uint[string] dictionary;
    foreach(line; stdin.byLine()) {
    // Break sentence into words
    // Add each word in the sentence to the vocabulary
        foreach(word; splitter(strip(line))) {
            if(word in dictionary) continue; // Nothing to do
            auto newID = dictionary.length;
            dictionary[word] = newID;
            writeln(newID, '\t', word);
        }
    }
}

The IDE says Error: undefined identifier splitter and since I am pretty experienced with Java, I guess the error means that the method doesn’t exist and that it therefor tried to handle it as a variable, but that doesn’t exist either. So I tried to change it to “split” instead. This produce another error at dictionary saying: Error: associative arrays can only be assigned values with immutable keys, not char[]

So I don’t really know what to do to solve this and make it work. So frustrating when code from books that are supposed to teach you, don’t work. I am using dmd2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:15:10+00:00Added an answer on June 15, 2026 at 9:15 pm

    The splitter you want is located in the std.algorithm.iteration module (previously std.array, but it moved in 2016). Add it to your import and that should go away.

    The other thing is dictionary[word]. That will have to be dictionary[word.idup] instead.

    The reason for that is the line brought in by stdin.byLine is in a temporary buffer (for maximum performance by avoiding memory allocations). When you get the next line, it will overwrite the previous one.

    You don’t want that in an AA: the keys will get all confused. The .idup makes a copy that never changes.

    (The reason the book doesn’t have the idup is probably because that the code there used to compile, but it didn’t really work right so that was considered a bug.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently reading the Machine Learning book by Tom Mitchell. When talking about
I'm very new to Unix, and currently taking a class learning the basics of
I'm diving into 3d programming a bit and am currently learning by writing a
Im currently learning Objective C, and so far Ive been using Automatic Reference Counting
I'm currently learning about concurrency in C++ and came across using a vector of
I'm currently taking a class where we are learning about synchronization of threads. The
Im currently learning c++ from a book called 'Ivor Hortons Beginning Visual c++ 2010'.
I am currently learning the language HLSL for effect files to my XNA game.
i'm currently learning about sockets with using java. I'm learning about TCP sockets and
I am currently learning C++ for a programming course. I noticed that my professor's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.