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 6046479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:14:41+00:00 2026-05-23T07:14:41+00:00

I am trying to define a replacement rule with optional argument color_RGBColor which should

  • 0

I am trying to define a replacement rule with optional argument color_RGBColor which should be replaced with Sequence[] when it is absent in the original expression:

style[line_Line, ___, 
  color_RGBColor: Unevaluated@Sequence[], ___] :> {color, line}

When RGBColor is present in the original expression, the rule works:

style[Line[], RGBColor[{}]] /. 
 style[line_Line, ___, 
   color_RGBColor: Unevaluated@Sequence[], ___] :> {color, line}

=> {RGBColor[{}], Line[]}

But when it is absent, it does not:

style[Line[], Thickness[0.01]] /. 
 Style[line_Line, ___, 
   color_RGBColor: Unevaluated@Sequence[], ___] :> {color, line}

=> style[Line[], Thickness[0.01]]

My questions are:

1) Why it does not work?

2) Is it possible to construct a single pattern which will work as desired?

  • 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-05-23T07:14:41+00:00Added an answer on May 23, 2026 at 7:14 am

    Your pattern does not work because of the way the pattern-matching works for the default (optional) arguments, and also because you restricted the head to be RGBColor. The problem is that the default argument value must match the pattern, while Unevaluated[Sequence[]] certainly does not match _RGBColor.

    You have several ways out. A first attempt is to weaken your type-checking:

    In[10]:= style[Line[],Thickness[0.01]]/.
    style[line_Line,___,color_: Unevaluated@Sequence[],___]:>{color,line}
    
    Out[10]= {Thickness[0.01],Line[]}
    

    But this does not work since the matching is incorrect – the typing is indeed too weak. The hacky way to make it work is this:

    In[14]:= style[Line[], RGBColor[{}]] /. 
     style[line_Line, ___, color : (_RGBColor | _Unevaluated) : 
        Unevaluated@Sequence[], ___] :> {Evaluate@color, line}
    
    
    Out[14]= {RGBColor[{}], Line[]}
    
    In[15]:= style[Line[], Thickness[0.01]] /. 
      style[line_Line, ___, color : (_RGBColor | _Unevaluated) : 
         Unevaluated@Sequence[], ___] :> {Evaluate@color, line}
    
    Out[15]= {Line[]}
    

    The recommended way to do it is this:

    In[18]:= style[Line[], Thickness[0.01]] /. 
    style[line_Line, ___, color : (_RGBColor | Automatic) : Automatic, ___] :> 
      If[color === Automatic, {line}, {color, line}]
    
    
    Out[18]= {Line[]}
    
    In[17]:= style[Line[], RGBColor[{}]] /. 
     style[line_Line, ___, color : (_RGBColor | Automatic) : Automatic, ___] :> 
       If[color === Automatic, {line}, {color, line}]
    
    
    Out[17]= {RGBColor[{}], Line[]}
    

    This feature of the pattern-matcher is not very widely known, so I will stress it again: the default value for the (optional) pattern x:ptrn:default must match ptrn. For another example of such behavior, see this Mathgroup discussion.

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

Sidebar

Related Questions

I'm trying to define a route configuration which will allow an optional 'region' in
i'm trying to define an scheme rule in XSD, for which a string is
I am trying to define an Enum and add valid common separators which used
I am trying to define which agile practices we are going to use, and
I'm trying to define a rule where one element is the perfect candidate for
I'm trying to define a block that takes a block as an argument. What's
I am trying to define a JQuery statement for finding elements which have a
I'm trying to define how to return XML content from my web API. Should
I was trying to: #define CommonAppData {commonappdata} but it yields: Compiler Error [ISPP] Expression
I'm trying to define a local resource in my xaml which is supposed to

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.